AC_PREREQ(2.59)
#
#  configure.ac
#
#  This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
#  project.
#
#  Copyright (C) 1998-2024 OpenLink Software
#
#  This project is free software; you can redistribute it and/or modify it
#  under the terms of the GNU General Public License as published by the
#  Free Software Foundation; only version 2 of the License, dated June 1991.
#
#  This program is distributed in the hope that it will be useful, but
#  WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
#  General Public License for more details.
#
#  You should have received a copy of the GNU General Public License along
#  with this program; if not, write to the Free Software Foundation, Inc.,
#  51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#


##########################################################################
##									##
##  Initializing							##
##									##
##########################################################################

m4_define(vos_major,	[7])
m4_define(vos_minor,	[2])
m4_define(vos_patch,	[12])
m4_define(vos_devel,	[])

AC_INIT([Virtuoso Open Source Edition (Column Store)],
	vos_major.vos_minor.vos_patch[]vos_devel,
	[vos.admin@openlinksw.com],
	[virtuoso-opensource])
AC_CONFIG_SRCDIR([libsrc/Dk.h])
AC_CONFIG_AUX_DIR([binsrc/config])
AC_CONFIG_MACRO_DIR([binsrc/config])
AC_CONFIG_HEADER([libsrc/Dk/config.h])

#
# Version variables
#
VOS_MAJOR="vos_major"
VOS_MINOR="vos_minor"
VOS_PATCH="vos_patch"

dnl
dnl You may need to change the next macro for older versions of automake:
dnl
dnl	AM_INIT_AUTOMAKE([1.6])
dnl	AM_INIT_AUTOMAKE([1.7])
dnl	AM_INIT_AUTOMAKE([1.8])
dnl	AM_INIT_AUTOMAKE([1.9 tar-ustar])
dnl	AM_INIT_AUTOMAKE([1.16 tar-ustar subdir-objects])
dnl
AM_INIT_AUTOMAKE([1.9 tar-ustar])

AM_MAINTAINER_MODE


##########################################################################
##									##
##  Check if makeconfig supports silent build rules                     ##
##									##
##########################################################################
m4_ifdef([AM_SILENT_RULES],
    [AM_SILENT_RULES([yes])
])


##########################################################################
##									##
##  Check system type							##
##									##
##########################################################################

AC_CANONICAL_HOST
AC_SUBST(host_cpu)
AC_SUBST(host_vendor)
AC_SUBST(host_os)


##########################################################################
##									##
##  Save configuration for later reuse					##
##									##
##########################################################################
echo creating config.nice
rm -f config.nice
cat >config.nice<<CONFIG_NICE_EOF
#!${SHELL-/bin/sh}
#
# Created by configure for $PACKAGE_STRING
#

# Environment
CONFIG_NICE_EOF
for var in SHELL CFLAGS CXXFLAGS CPPFLAGS LDFLAGS INCLUDES LIBS CC CXX
do
    eval val=\$$var
    if test -n "$val"
    then
	echo "$var=\"$val\"; export $var" >> config.nice
    fi
done

echo "" >> config.nice
echo ${SHELL} "\"$0\" \\" >> config.nice

eval "set -- $ac_configure_args"

for arg
do
    echo "\"$arg\" \\" >> config.nice
done

echo '"$@"' >> config.nice
chmod +x config.nice


##########################################################################
##									##
##  Set Layout for Virtuoso						##
##									##
##########################################################################
AC_PREFIX_DEFAULT(/usr/local/virtuoso-opensource)

AC_MSG_CHECKING(for Virtuoso installation layout)
AC_ARG_WITH(layout, [dnl
AC_HELP_STRING([--with-layout=LAYOUT], [Choose installation layout])dnl
],
[ case "${withval}" in
    yes|no)	VIRTUOSO_LAYOUT=unset ;;
    *)		VIRTUOSO_LAYOUT=${withval} ;;
  esac
], [VIRTUOSO_LAYOUT=unset])


#
#  Defaults for Layout
#

case ${VIRTUOSO_LAYOUT} in
  unset)						# No Layout set
	virtuoso_layout="default"
	vaddir=$datadir/virtuoso/vad
	docdir=$datadir/virtuoso/doc
	htmldocdir=$datadir/virtuoso/doc/html
	pdfdocdir=$datadir/virtuoso/doc/pdf
	demodir=$localstatedir/lib/virtuoso/demo
	dbdir=$localstatedir/lib/virtuoso/db
	httprootdir=$localstatedir/lib/virtuoso/vsp
	hostingdir=$libdir/virtuoso/hosting
	clidir=$libdir/virtuoso/cli
	;;

  [[Gg]][[Nn]][[Uu]])					# GNU
	virtuoso_layout="GNU"
	test "x$prefix" = xNONE && prefix=/usr/local
	vaddir=$datadir/virtuoso/vad
	docdir=$datadir/virtuoso/doc
	htmldocdir=$datadir/virtuoso/doc/html
	pdfdocdir=$datadir/virtuoso/doc/pdf
	demodir=$localstatedir/lib/virtuoso/demo
	dbdir=$localstatedir/lib/virtuoso/db
	httprootdir=$localstatedir/lib/virtuoso/vsp
	hostingdir=$libdir/virtuoso/hosting
	clidir=$libdir/virtuoso/cli
	;;

  [[Dd]][[Ee]][[Bb]][[Ii]][[Aa]][[Nn]])			# Debian
	virtuoso_layout="Debian"
	if test "x$prefix" = "xNONE"
	then
		prefix=/usr
		localstatedir=/var
	fi
	VIRTPKGDIR=virtuoso-opensource-$VOS_MAJOR
	vaddir=$datadir/$VIRTPKGDIR/vad
	docdir=$datadir/doc/$VIRTPKGDIR
	htmldocdir=$datadir/doc/$VIRTPKGDIR/html
	pdfdocdir=$datadir/doc/$VIRTPKGDIR/pdf
	demodir=$localstatedir/lib/$VIRTPKGDIR/demo
	dbdir=$localstatedir/lib/$VIRTPKGDIR/db
	httprootdir=$localstatedir/lib/$VIRTPKGDIR/vsp
	hostingdir=$libdir/$VIRTPKGDIR/hosting
	clidir=$libdir/cli/$VIRTPKGDIR/
	;;

  [[Gg]][[Ee]][[Nn]][[Tt]][[Oo]][[Oo]])			# Gentoo
	virtuoso_layout="Gentoo"
	if test "x$prefix" = "xNONE"
	then
		prefix=/usr
		localstatedir=/var
	fi
	VIRTPKGDIR=virtuoso-$VOS_MAJOR
	vaddir=$datadir/$VIRTPKGDIR/vad
	docdir=$datadir/doc/$VIRTPKGDIR
	htmldocdir=$datadir/doc/$VIRTPKGDIR/html
	pdfdocdir=$datadir/doc/$VIRTPKGDIR/pdf
	demodir=$localstatedir/lib/$VIRTPKGDIR/demo
	dbdir=$localstatedir/lib/$VIRTPKGDIR/db
	httprootdir=$localstatedir/lib/$VIRTPKGDIR/vsp
	hostingdir=$libdir/$VIRTPKGDIR/hosting
	clidir=$libdir/$VIRTPKGDIR/cli
	;;

  [[Rr]][[Ee]][[Dd]][[Hh]][[Aa]][[Tt]])			# RedHat
	virtuoso_layout=RedHat
	if test "x$prefix" = "xNONE"
	then
		prefix=/usr
		localstatedir=/var
	fi
	vaddir=$datadir/virtuoso/vad
	docdir=$datadir/doc/virtuoso
	htmldocdir=$datadir/doc/virtuoso/html
	pdfdocdir=$datadir/doc/virtuoso/pdf
	demodir=$localstatedir/lib/virtuoso/demo
	dbdir=$localstatedir/lib/virtuoso/db
	httprootdir=$localstatedir/lib/virtuoso/vsp
	hostingdir=$libdir/virtuoso/hosting
	clidir=$libdir/virtuoso/cli
	;;

  [[Oo]][[Pp]][[Ee]][[Nn]][[Ss]][[Uu]][[Ss]][[Ee]])	# openSUSE
	virtuoso_layout=openSUSE
	if test "x$prefix" = "xNONE"
	then
		prefix=/usr
		localstatedir=/var
	fi
	vaddir=$datadir/virtuoso/vad
	docdir=$datadir/doc/packages/virtuoso
	htmldocdir=$datadir/doc/packages/virtuoso/html
	pdfdocdir=$datadir/doc/packages/virtuoso/pdf
	demodir=$localstatedir/lib/virtuoso/demo
	dbdir=$localstatedir/lib/virtuoso/db
	httprootdir=$localstatedir/lib/virtuoso/vsp
	hostingdir=$libdir/virtuoso/hosting
	clidir=$libdir/virtuoso/cli
	;;

  [[Ff]][[Rr]][[Ee]][[Ee]][[Bb]][[Ss]][[Dd]])		# FreeBSD
	virtuoso_layout=FreeBSD
	if test "x$prefix" = "xNONE"
	then
		prefix=/usr
		localstatedir=/var
	fi
	vaddir=$datadir/virtuoso/vad
	docdir=$datadir/virtuoso/doc
	htmldocdir=$datadir/virtuoso/doc/html
	pdfdocdir=$datadir/virtuoso/doc/pdf
	demodir=$localstatedir/lib/virtuoso/demo
	dbdir=$localstatedir/lib/virtuoso/db
	httprootdir=$localstatedir/lib/virtuoso/vsp
	hostingdir=$libdir/virtuoso/hosting
	clidir=$libdir/virtuoso/cli
	;;

  [[Oo]][[Pp]][[Tt]])					# /opt
	virtuoso_layout=opt
	test "x$prefix" = xNONE && prefix=/opt/virtuoso-opensource
	vaddir='${prefix}/vad'
	docdir='${prefix}/doc'
	htmldocdir='${prefix}/doc/html'
	pdfdocdir='${prefix}/doc/pdf'
	demodir='${prefix}/demo'
	dbdir='${prefix}/database'
	httprootdir='${prefix}/vsp'
	hostingdir='${prefix}/hosting'
	clidir='${prefix}/lib'
	;;

 [[Oo]][[Pp]][[Ee]][[Nn]][[Ll]][[Ii]][[Nn]][[Kk]])	# OpenLink
 	virtuoso_layout=openlink
	test "x$prefix" = xNONE && prefix=/usr/local/virtuoso-opensource
	vaddir='${prefix}/vad'
	docdir='${prefix}/doc'
	htmldocdir='${prefix}/doc/html'
	pdfdocdir='${prefix}/doc/pdf'
	demodir='${prefix}/demo'
	dbdir='${prefix}/database'
	httprootdir='${prefix}/vsp'
	hostingdir='${prefix}/hosting'
	clidir='${prefix}/lib'
	;;

  *)							# UNKNOWN
  	AC_MSG_RESULT(unknown)
	echo ""
	echo "AC_HELP_STRING([Supported layouts:], [Debian FreeBSD GNU OpenLink opt RedHat])"
	echo ""
	AC_MSG_ERROR([unable to continue])
	;;
esac
AC_MSG_RESULT([${virtuoso_layout}])

AC_SUBST(dbdir)
AC_SUBST(demodir)
AC_SUBST(docdir)
AC_SUBST(hostingdir)
AC_SUBST(htmldocdir)
AC_SUBST(httprootdir)
AC_SUBST(pdfdocdir)
AC_SUBST(vaddir)
AC_SUBST(clidir)

##########################################################################
##									##
##  Set TOP variable for OpenLink Source Tree				##
##									##
##########################################################################

TOP=`pwd`
LIBDIR=$TOP/lib
BINDIR=$TOP/bin
INCDIR=$TOP/include
#OPLDIR=$TOP/openlink
AC_SUBST(TOP)
AC_SUBST(LIBDIR)
AC_SUBST(BINDIR)
AC_SUBST(INCDIR)
#AC_SUBST(OPLDIR)


##########################################################################
##									##
##  Check C compiler and features					##
##									##
##########################################################################

AC_PROG_CC
AC_PROG_CXX
AC_PROG_CC_C_O
AC_LANG_C
AC_PROG_LD
AC_SUBST(LD)

AC_PROG_CPP
AC_PATH_PROG(JAVACPP, [cpp], [/lib/cpp], [/usr/bin:/lib:$PATH])


##########################################################################
##									##
##  Various UNIX version specific checks				##
##									##
##########################################################################

AC_AIX
AC_ISC_POSIX
AC_MINIX

##########################STAGING area####################################
##########################STAGING area####################################


##########################################################################
##									##
##  Check specific C constructions 					##
##									##
##########################################################################

dnl AC_C_CROSS			dnl this has been merged into AC_PROG_CC
AC_C_BIGENDIAN
AC_C_CONST 			dnl this used to be AC_CONST
AC_C_INLINE
AC_C_CHAR_UNSIGNED
AC_C_LONG_DOUBLE


##########################################################################
##									##
##  Check lengths C datatypes	 					##
##									##
##########################################################################

AC_CHECK_SIZEOF(char)
AC_CHECK_SIZEOF(short)
AC_CHECK_SIZEOF(unsigned)
AC_CHECK_SIZEOF(int)
AC_CHECK_SIZEOF(long)
AC_CHECK_SIZEOF(long long)
AC_CHECK_SIZEOF(float)
AC_CHECK_SIZEOF(double)
AC_CHECK_SIZEOF(long double)
AC_CHECK_SIZEOF(char *)
AC_CHECK_SIZEOF(void *)
dnl AC_CHECK_SIZEOF(void(*)())	dnl Could not be checked this way
dnl OBSOLETE AC_INT_16_BITS	dnl now checked by AC_CHECK_SIZE(int)

#
#  Check if this is a 64bit build
#
if test "x$ac_cv_sizeof_void_p" != 'x8'
then
    AC_ERROR([The current version of $PACKAGE_NAME can only be built on 64bit platforms])
fi

##########################################################################
##									##
##  Check for various programms						##
##									##
##########################################################################

##  Force install-sh to be accessed via an absolute path:
ac_install_sh="$TOP/$ac_install_sh"
AC_PROG_INSTALL

AC_PROG_MAKE_SET
AC_PROG_LN_S

## We favor yacc above bizon or byacc, therefor we do not use AC_PROG_YACC
AC_PROG_YACC
## AC_CHECK_PROGS(YACC, yacc byacc 'bison -l', yacc)


AC_PATH_PROG(HTMLDOC, htmldoc)
AM_CONDITIONAL(WITH_HTMLDOC, test "x$HTMLDOC" != "x")

AM_PROG_LEX

AC_PATH_PROG(FLEX, flex, flex)
AC_PATH_PROG(GAWK, gawk, gawk)
AC_PATH_PROG(GPERF, gperf, gperf)
AC_PATH_PROG(PERL, perl, perl)
AC_PATH_PROG(PYTHON, python, python)
AC_PATH_PROG(RUBY, ruby, ruby)
#AC_DECL_YYTEXT

##########################################################################
##									##
##  Use the new LibTool GNU package					##
##									##
##########################################################################
LT_INIT		dnl was AC_PROG_LIBTOOL

#
#  Use our own libtool so we can perform Universal builds
#
case $host in
  *-darwin14*)
	;;
  *-darwin*)
	LIBTOOL='$(SHELL) $(top_srcdir)/bin/libtool.macosx'
	;;
esac

##########################################################################
##									##
##  Check various headers						##
##									##
##########################################################################

AC_HEADER_STDC 			dnl this used to be AC_STDC_HEADERS
AC_HEADER_DIRENT		dnl this used to be AC_DIR_HEADER
AC_HEADER_MAJOR
AC_HEADER_STAT 			dnl this used to be AC_STAT_MACROS_BROKEN
AC_HEADER_TIME 			dnl this used to be AC_TIME_WITH_SYS_TIME
AC_HEADER_SYS_WAIT

AC_CHECK_HEADERS(unistd.h limits.h sys/param.h fcntl.h string.h memory.h \
		sys/timeb.h sys/sockio.h sys/resource.h \
		malloc.h sys/select.h sys/time.h wchar.h wctype.h \
		pwd.h grp.h sys/mman.h execinfo.h)


##########################################################################
##									##
##  Check various typedefs in include headers				##
##									##
##########################################################################

AC_TYPE_MODE_T
AC_TYPE_OFF_T
AC_TYPE_PID_T 		dnl this used to be AC_PID_T
AC_TYPE_SIGNAL		dnl this used to be AC_RETSIGTYPE
AC_TYPE_SIZE_T 		dnl this used to be AC_SIZE_T
AC_TYPE_UID_T


##########################################################################
##									##
##  Check various structs in include headers				##
##									##
##########################################################################

AC_STRUCT_ST_BLKSIZE
AC_STRUCT_ST_BLOCKS
AC_STRUCT_ST_RDEV
AC_STRUCT_TM
AC_CHECK_TYPES(ptrdiff_t)
dnl AC_STRUCT_TIMEZONE 		dnl this used to be AC_TIMEZONE


##########################################################################
##									##
##  Check other structs in include headers				##
##									##
##########################################################################

#AC_DECL_SYS_SIGLIST
#AC_EGREP_HEADER(tm_gmtoff, time.h, AC_DEFINE(HAVE_TM_GMTOFF))
#AC_EGREP_HEADER(tm_tzadj, time.h, AC_DEFINE(HAVE_TM_TZADJ))

AC_CACHE_CHECK([for tm_gmtoff in struct tm], ac_cv_struct_tm_gmtoff,
[AC_TRY_COMPILE([#include <sys/types.h>
#include <$ac_cv_struct_tm>], [struct tm tm; tm.tm_gmtoff;],
  ac_cv_struct_tm_gmtoff=yes, ac_cv_struct_tm_gmtoff=no)])
if test "$ac_cv_struct_tm_gmtoff" = yes; then
  AC_DEFINE(HAVE_TM_GMTOFF,1, [Define if struct tm contains tm_gmtoff] )
fi

AC_CACHE_CHECK([for tm_tzadj in struct tm], ac_cv_struct_tm_tzadj,
[AC_TRY_COMPILE([#include <sys/types.h>
#include <$ac_cv_struct_tm>], [struct tm tm; tm.tm_tzadj;],
  ac_cv_struct_tm_tzadj=yes, ac_cv_struct_tm_tzadj=no)])
if test "$ac_cv_struct_tm_tzadj" = yes; then
  AC_DEFINE(HAVE_TM_TZADJ,1, [Define if struct tm contains tm_tzadj] )
fi


##########################################################################
##									##
##  Check libraries							##
##									##
##########################################################################

# The following three (nsl,inet,socket) are needed on Sequent;
# the order of checking must be this.  Most SVR4 platforms will
# need -lsocket and -lnsl.  However on SGI IRIX 5, these exist but
# broken.  I see no elegant solution (probably CHECK_LIB should be
# fixed to only add the library if the given entry point is not
# satisfied without it).
if test "$ac_sys_system" != IRIX
then
AC_CHECK_LIB(nsl, t_open, [VLIBS="-lnsl $VLIBS"]) # SVR4
AC_CHECK_LIB(inet, gethostbyname, [VLIBS="-linet $VLIBS"], [], -lnsl) # Sequent
AC_CHECK_LIB(socket, socket, [VLIBS="-lsocket $VLIBS"], [], $VLIBS) # SVR4 sockets
fi
AC_CHECK_LIB(m, cos, [VLIBS="-lm $VLIBS"]) # complex math

##########################################################################
##									##
##  Check various functions						##
##									##
##########################################################################

#AC_FUNC_ALLOCA 			dnl this used to be AC_ALLOCA
#AC_FUNC_CLOSEDIR_VOID
#AC_FUNC_GETMNTENT
#AC_FUNC_GETPGRP
AC_FUNC_MEMCMP
#AC_FUNC_MMAP
AC_FUNC_SETVBUF_REVERSED 	dnl this used to be AC_SETVBUF_REVERSED
#AC_FUNC_STRCOLL
#AC_FUNC_STRFTIME
#AC_FUNC_UTIME_NULL
AC_FUNC_FORK
#AC_FUNC_VPRINTF
#AC_FUNC_WAIT3
AC_FUNC_CHOWN
AC_FUNC_STRERROR_R
dnl not used AC_FUNC_GETLOADAVG

##########################################################################
##									##
##  Check other functions						##
##									##
##########################################################################

AC_CHECK_FUNCS(getpagesize gettimeofday strtok_r ftruncate fchmod fsync ftime localtime_r gmtime_r syslog)
AC_CHECK_FUNCS(snprintf vsnprintf)

AC_CHECK_FUNCS(cwprintf fgetws fputws fwprintf iswdigit iswlower iswspace iswupper putwc putwchar putws)
AC_CHECK_FUNCS(swprintf swscanf towlower towupper wcscasecmp wcscat wcschr wcscmp wcscpy wcsdup wcsicmp)
AC_CHECK_FUNCS(wcslen wcsncasecmp wcsncat wcsncmp wcsncpy wcsnicmp wcsrchr wcsstr wexecvp wfopen wgetenv)
AC_CHECK_FUNCS(wperror wprintf wtoi wtol wgetpass wgetpassphrase)

AC_CHECK_FUNCS(getpwnam getgrnam chmod getpwuid getgrgid setuid)
AC_CHECK_FUNCS(putenv setenv)
AC_CHECK_FUNCS(strerror)
AC_CHECK_FUNCS(strdup)
AC_CHECK_FUNCS(getrusage)
AC_CHECK_FUNCS(memmove memmem memcpy)
AC_CHECK_FUNCS(mkstemp64 mkstemp)
AC_CHECK_FUNCS(strftime stpcpy)
AC_CHECK_FUNCS(gethrtime)

AC_MSG_CHECKING(for sys_errlist)
AC_TRY_LINK([
#include <stdio.h>
#include <errno.h>
], [
 void *err = (void *) sys_errlist;
], [
 AC_DEFINE([HAVE_SYS_ERRLIST], 1, [if having SYS_ERRLIST])
 AC_MSG_RESULT(yes)
], [
 AC_MSG_RESULT(no)
])

AC_CACHE_CHECK([whether va_copy exists], ac_cv_have_va_copy, [
	AC_TRY_LINK(
		[#include <stdarg.h>
		 va_list x,y;],
	    	[va_copy(x,y);],
		[ ac_cv_have_va_copy="yes" ],
		[ ac_cv_have_va_copy="no" ]
	)
])
if test "x$ac_cv_have_va_copy" = "xyes" ; then
	AC_DEFINE(HAVE_VA_COPY, 1, [Define if va_copy exists])
fi

AC_CACHE_CHECK([whether __va_copy exists], ac_cv_have___va_copy, [
	AC_TRY_LINK(
		[#include <stdarg.h>
		 va_list x,y;],
	    	[__va_copy(x,y);],
		[ ac_cv_have___va_copy="yes" ],
		[ ac_cv_have___va_copy="no" ]
	)
])
if test "x$ac_cv_have___va_copy" = "xyes" ; then
	AC_DEFINE(HAVE___VA_COPY, 1, [Define if __va_copy exists])
fi


##########################################################################
##                                                                     ##
##check for clock_gettime which may require an extra library           ##
##                                                                     ##
##########################################################################
AC_SEARCH_LIBS(clock_gettime, [rt posix4], [
       AC_DEFINE([HAVE_CLOCK_GETTIME], [1], [Define to 1 if you have the clock_gettime function.])
])


##########################################################################
##									##
##check for presense of flock & the constants LOCK_EX and LOCK_UN	##
##									##
##########################################################################

AC_MSG_CHECKING(for flock in <sys/file.h>)
AC_TRY_LINK([
#include <sys/file.h>
], [
return (flock (0, LOCK_EX) || flock (0, LOCK_UN));
], [
AC_DEFINE(HAVE_FLOCK_IN_SYS_FILE, 1, [Define to 1 if you have flock defined into <sys/file.h> header file])
AC_MSG_RESULT(yes)], AC_MSG_RESULT(no))


##########################################################################
##									##
##  Check OS capabilities						##
##									##
##########################################################################

AC_SYS_INTERPRETER
AC_SYS_LONG_FILE_NAMES
AC_SYS_RESTARTABLE_SYSCALLS


##########################################################################
##									##
##  OPENLINK SOFTWARE OWN TESTS						##
##									##
##########################################################################

##########################################################################
##									##
##  Default C compiler flags						##
##									##
##########################################################################

CCOPT=""
CCDEFS=""
CCWARN=""
CCDEBUG=""
CCLIBS=""

AC_CHECKING([default compiler values])
if eval "${CC-cc} $CFLAGS $AM_LDFLAGS -o binsrc/config/ccdefs binsrc/config/ccdefs.c" ; then
    eval `binsrc/config/ccdefs`
fi

AC_ARG_WITH(debug, [dnl
AC_HELP_STRING([--with-debug], [debugging code])dnl
], [ with_debug="$withval" ],
   [ with_debug="no" ])
if test "x$with_debug" = "xyes"; then
    changequote({,})
    CFLAGS=`echo "$CFLAGS" | $SED -e 's/-O[0-9s]*//g'`
    CXXFLAGS=`echo "$CXXFLAGS" | $SED -e 's/-O[0-9s]*//g'`
    changequote([,])

    CCOPT="-g"
    AM_LDFLAGS="-g"
    CCDEBUG=""
else
    AM_LDFLAGS="-s"
fi


#AC_CHECKING(for suspicious C compiler)
#AC_TRY_COMPILE([ ], [struct { long l; void *d; } *x;
#  (char *) x += 1; ], [ ] , [CCDEFS="$CCDEFS -DSUSPICIOUS_C_COMPILER"])

AC_SUBST(CCDEBUG)
AC_SUBST(CCWARN)
AC_SUBST(CCDEFS)
AC_SUBST(CCOPT)
AC_SUBST(CCLIBS)

AC_MSG_CHECKING([for uuid_t])
AC_TRY_COMPILE(
[
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
],
[
 uuid_t x;
],
[
 AC_DEFINE(UUID_T_DEFINED, 1, [Define to 1 if you have uuid_t defined])
 AC_MSG_RESULT([yes])
],
[
 AC_MSG_RESULT([no])
])


##########################################################################
##									##
##  Configure Virtuoso extensions 					##
##									##
##########################################################################
AC_SUBST(BUILD_OPTS)
BUILD_OPTS=""
srvrlibs=""
clntlibs=""

AC_ARG_ENABLE(xml, [dnl
AC_HELP_STRING([--enable-xml], [enable XML extension (default)])
AC_HELP_STRING([--disable-xml], [disable XML extension])dnl
], [
     case "${enableval}" in
       yes)	with_xml="yes";;
       no)	AC_MSG_ERROR(Xml extension required for Virtuoso) ;;
       *)	AC_MSG_ERROR(bad value ${enableval} for --enable-xml) ;;
     esac
  ],
  [ with_xml="yes" ]
)

if test "$with_xml" = "yes"; then
    BUILD_OPTS="$BUILD_OPTS xml"
    AC_DEFINE(BIF_XML, 1, [XML support])
    libxml_file=$LIBDIR/libxml.la
    ccincl="$ccincl -I$TOP/libsrc/Xml.new"
fi
AC_SUBST(libxml_file)

AC_SUBST(CCOPT)


##########################################################################
#                                                                        #
# Kerberos client                                                        #
#                                                                        #
##########################################################################
AC_ARG_ENABLE(krb, [dnl
AC_HELP_STRING([--enable-krb(=DIR)], [enable Kerberos extension])
AC_HELP_STRING([--disable-krb], [disable Kerberos extension (default)])dnl
], [
     case "${enableval}" in
       yes)	with_krb="yes";;
       no)	with_krb="no";;
       /*)	with_krb="${enableval}";;
       *)	AC_MSG_ERROR(bad value ${enableval} for --disable-krb) ;;
     esac
  ],
  [ with_krb="no" ]
)

if test "$with_krb" != "no"; then
    libkrb="-lkrb5 -lcom_err -lgssapi_krb5 -lk5crypto -lkrb5"
    krbinc=""
    if test "$with_krb" != "yes"; then
      libkrb="-L$with_krb/lib $libkrb"
      krbinc="-I$with_krb/include"
    fi
    AC_CHECK_LIB(krb5,krb5_init_context,
		 [
		  with_krb="yes"
		 ],
		 [
		  with_krb="no"
		 ],
		 [ $libkrb ])
fi

if test "$with_krb" != "no"; then
    save_CPPFLAGS=$CPPFLAGS
    CPPFLAGS="$krbinc $CPPFLAGS"
    AC_CHECK_HEADERS(krb5.h gssapi/gssapi.h gssapi/gssapi_generic.h gssapi/gssapi_krb5.h,,
		      [
		       with_krb="no"
		      ])
    CPPFLAGS=$save_CPPFLAGS
fi
if test "$with_krb" != "no"; then
    AC_DEFINE(_KERBEROS, 1, "Kerberos support")
    AC_DEFINE(GSSAPI, 1, "Kerberos mode")
    BUILD_OPTS="$BUILD_OPTS krb"
    if test "$with_krb" != "yes"; then
      ccincl="$ccincl -I$with_krb/include"
    fi
    srvrlibs="$srvrlibs $libkrb"
fi
AM_CONDITIONAL(WITH_KERBEROS, test "x$with_krb" != "xno" )


##########################################################################
#                                                                        #
# OpenSSL                                                                #
#                                                                        #
##########################################################################
AC_ARG_ENABLE(openssl, [dnl
AC_HELP_STRING([--enable-openssl(=DIR)], [enable OpenSSL support (default)])
AC_HELP_STRING([--disable-openssl], [disable OpenSSL support])dnl
], [
     case "${enableval}" in
       yes)	openssl_dir="/usr" ;;
       no)	openssl_dir="no" ;;
       /*)	openssl_dir="${enableval}" ;;
       *)	AC_MSG_ERROR(bad value ${enableval} for --disable-openssl) ;;
     esac
  ],
  [ openssl_dir="/usr" ]
)

if test "x$openssl_dir" = "xno"
then
    openssl_VERSION=""
    openssl_CFLAGS=""
    openssl_LDFLAGS=""
elif test "x$openssl_dir" = "x/usr"
then
    openssl_VERSION=`openssl version`
    openssl_CFLAGS=""
    openssl_LDFLAGS="-lssl -lcrypto"
else
    openssl_VERSION=`$openssl_dir/bin/openssl version`
    openssl_CFLAGS="-I$openssl_dir/include"
    openssl_LDFLAGS="-L$openssl_dir/lib -lssl -lcrypto"
fi

if test "$with_krb" = "no"
then
  openssl_CFLAGS="$openssl_CFLAGS -DOPENSSL_NO_KRB5"
fi

if test "x$openssl_dir" != "xno"
then
	save_CFLAGS="$CFLAGS"
	save_LIBS="$LIBS"

	CFLAGS="$CFLAGS $openssl_CFLAGS"
	LIBS="$LIBS $openssl_LDFLAGS"
	case $host in
	*-solaris*)
		LIBS="$LIBS -lsocket"
		;;

	*-sunos*)
		LIBS="$LIBS -lsocket"
		;;

	*-linux*)
		LIBS="$LIBS -ldl -lpthread"
		;;
	esac

	AC_MSG_CHECKING([OpenSSL version])
	AC_TRY_COMPILE([
	#include <openssl/opensslv.h>
	], [
	#if OPENSSL_VERSION_NUMBER < 0x0090801fL
	#error OpenSSL version too old 
	#endif
	    ],[
	      AC_MSG_RESULT([>= 0.9.8e])
	    ],[
	      AC_MSG_ERROR([OpenSSL version 0.9.8e or greater is required.])
	    ])

	AC_MSG_CHECKING([OpenSSL version])
	AC_TRY_COMPILE([
	#include <openssl/opensslv.h>
	],[
	#ifdef LIBRESSL_VERSION_NUMBER
	/* LibreSSL defines OPENSSL_VERSION_NUMBER 0x20000000L but uses a compatible API to OpenSSL v1.0.x */
	#elif OPENSSL_VERSION_NUMBER < 0x1020000fL
	/* OpenSSL versions 0.9.8e - 1.1.1 are supported */
       #elif OPENSSL_VERSION_NUMBER < 0x30200000L
       /* OpenSSL version 3.1.x is supported */
	#else
	#error OpenSSL version too new
	#endif
	    ],[
             AC_MSG_RESULT([$openssl_VERSION is supported])
	    ],[
             AC_MSG_ERROR([$openssl_VERSION is currently not supported.])
	    ])

	AC_MSG_CHECKING([usability of the OpenSSL header files and library in ${openssl_dir}])
	AC_TRY_RUN([
	#include <openssl/rsa.h>
	#include <openssl/crypto.h>
	#include <openssl/x509.h>
	#include <openssl/pem.h>
	#include <openssl/ssl.h>
	#include <openssl/err.h>
	#include <openssl/bio.h>
	#include <openssl/asn1.h>
	#include <openssl/pkcs12.h>
	#include <openssl/rand.h>
	#include <stdio.h>
	#include <string.h>
	int
	main ()
	{
	    SSL_METHOD *ssl_server_method = NULL;
	    SSL_CTX *ssl_server_ctx = NULL;
	    unsigned char tmp[1024];

	    SSL_load_error_strings();
	    ERR_load_X509_strings();
	    ERR_load_PKCS12_strings();
	#ifndef WIN32
	    RAND_bytes (tmp, sizeof(tmp));
	    RAND_add (tmp, sizeof(tmp), (double)(sizeof(tmp)));
	#endif
	    SSLeay_add_ssl_algorithms();
	    PKCS12_PBE_add ();

	    ssl_server_method = SSLv23_client_method();
	    ssl_server_ctx = SSL_CTX_new (ssl_server_method);

	    if (!ssl_server_ctx)
	    {
		ERR_print_errors_fp(stderr);
		return(-1);
	    }

	  return 0;
	}],
	[
	 AC_MSG_RESULT(good)
	 BUILD_OPTS="$BUILD_OPTS ssl"
	 ccincl="$ccincl $openssl_CFLAGS"
	 srvrlibs="$srvrlibs $openssl_LDFLAGS"
	 clntlibs="$clntlibs $openssl_LDFLAGS"
	 AC_DEFINE(_SSL, 1, [OpenSSL])
	],
	[
	 AC_MSG_ERROR([bad. Check config.log for details])
	])
	LIBS="$save_LIBS"
	CFLAGS="$save_CFLAGS"
fi
AC_SUBST(openssl_CFLAGS)
AC_SUBST(openssl_LDFLAGS)



##########################################################################
#                                                                        #
# OpenLDAP                                                               #
#                                                                        #
##########################################################################
AC_ARG_ENABLE(openldap, [dnl
AC_HELP_STRING([--enable-openldap(=DIR)], [enable OpenLDAP support (default)])
AC_HELP_STRING([--disable-openldap], [disable OpenLDAP support])dnl
], [
     case "${enableval}" in
       yes)	with_ldap="yes" ;;
       no)	with_ldap="no" ;;
       /*)	with_ldap="${enableval}" ;;
       *)	AC_MSG_ERROR(bad value ${enableval} for --disable-openldap) ;;
     esac
  ],
  [ with_ldap="yes" ]
)

if test "x$with_ldap" != "xno"
then
    AC_MSG_CHECKING([OpenLDAP library usability])
    save_CPPFLAGS="$CPPFLAGS"
    save_LIBS="$LIBS"
    old_LD_LIBRARY_PATH="$LD_LIBRARY_PATH"
    case "$with_ldap" in
	yes)
	   openldap_CFLAGS=""
	   openldap_LDFLAGS="-lldap -llber"
	   ;;
	*)
	   openldap_CFLAGS="-I$with_ldap/include"
	   openldap_LDFLAGS="-L$with_ldap/lib -lldap -llber"
	   LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$with_ldap/lib"
	   export LD_LIBRARY_PATH
	   ;;
    esac
    CPPFLAGS="$CPPFLAGS $openldap_CFLAGS"
    LIBS="$LIBS $openldap_LDFLAGS"
    AC_TRY_RUN([
#include <ldap.h>
#include <stdio.h>
#include <string.h>
int
main ()
{
  LDAP *ld = ldap_init ("localhost", LDAP_PORT);
  if (!ld)
    {
       fprintf (stderr, "Can't initialize the LDAP lib");
       return 1;
    }
  return 0;
}],
[
 AC_MSG_RESULT(good)
 BUILD_OPTS="$BUILD_OPTS ldap"
 srvrlibs="$srvrlibs $openldap_LDFLAGS"
 AC_DEFINE(_LDAP, 1, [OpenLDAP])
],
[
 AC_MSG_RESULT(bad. Check config.log for details)
 with_ldap="no"
])
    LIBS="$save_LIBS"
    CPPFLAGS="$save_CPPFLAGS"
    LD_LIBRARY_PATH="$old_LD_LIBRARY_PATH"
fi
AM_CONDITIONAL(WITH_LDAP, test "x$with_ldap" != "xno" )
AC_SUBST(openldap_CFLAGS)
AC_SUBST(openldap_LDFLAGS)


##########################################################################
#                                                                        #
# POP3/NNTP support --imsg                                               #
#                                                                        #
##########################################################################
AC_ARG_ENABLE(imsg, [dnl
AC_HELP_STRING([--enable-imsg], [enable POP3 and NNTP extension (default)])
AC_HELP_STRING([--disable-imsg], [disable POP3 and NNTP extension])dnl
], [
     case "${enableval}" in
       yes)	with_imsg="yes";;
       no)	with_imsg="no";;
       *)	AC_MSG_ERROR(bad value ${enableval} for --enable-imsg) ;;
     esac
  ],
  [ with_imsg="yes" ]
)

if test "$with_imsg" = "yes"; then
    BUILD_OPTS="$BUILD_OPTS imsg"
    AC_DEFINE(_IMSG, 1, [POP3 and NNTP extension])
fi
AM_CONDITIONAL(WITH_IMSG, test "x$with_imsg" = "xyes")


##########################################################################
#                                                                        #
# PL Debugger support                                                    #
#                                                                        #
##########################################################################
AC_ARG_ENABLE(pldebug, [dnl
AC_HELP_STRING([--enable-pldebug], [enable Virtuoso/PL debugger support (default)])
AC_HELP_STRING([--disable-pldebug], [disable Virtuoso/PL debugger support])dnl
], [
     case "${enableval}" in
       yes)	with_pldebug="yes" ;;
       no)	with_pldebug="no" ;;
       *)	AC_MSG_ERROR(bad value ${enableval} for --enable-pldebug) ;;
     esac
  ],
  [ with_pldebug="yes" ]
)

if test "$with_pldebug" = "yes"; then
    BUILD_OPTS="$BUILD_OPTS pldebug"
    AC_DEFINE(PLDBG, 1, [Virtuoso/PL debugger])
    PLSTATS=PLDBG
    AC_SUBST(PLSTATS)
fi
AM_CONDITIONAL(WITH_PLDEBUG, test "x$with_pldebug" = "xyes")


##########################################################################
#                                                                        #
# Rendezvous                                                             #
#                                                                        #
##########################################################################
with_rvous_dir=""
AC_ARG_ENABLE(rendezvous, [dnl
AC_HELP_STRING([--enable-rendezvous(=DIR)], [enable rendezvous extension])
AC_HELP_STRING([--disable-rendezvous], [disable rendezvous extension (default)])dnl
], [
     case "${enableval}" in
       yes)	with_rvous="yes" ;;
       no)	with_rvous="no" ;;
       /*)	with_rvous="yes"; with_rvous_dir="${enableval}" ;;
       *)	AC_MSG_ERROR(bad value ${enableval} for --enable-rendezvous) ;;
     esac
  ],
  [ with_rvous="no" ]
)

if test "$with_rvous" = "yes"; then
    BUILD_OPTS="$BUILD_OPTS rendezvous"
    AC_DEFINE(_RENDEZVOUS, 1, [Define to 1 to build with Rendezvous support.])
    if test -z "$with_rvous_dir"
    then
	    librv="-lrendezvous"
    else
	    librv="${with_rvous_dir}/build/librendezvous.la"
	    ccincl="$ccincl -I${with_rvous_dir}/build/tmp -I${with_rvous_dir}/mDNSCore -I${with_rvous_dir}/mDNSPosix"
    fi
    srvrlibs="$srvrlibs $librv"
fi


##########################################################################
#                                                                        #
# PHP 5.x hosting                                                        #
#                                                                        #
##########################################################################

with_php5="no"
AC_ARG_ENABLE(php5, [dnl
AC_HELP_STRING([--enable-php5(=DIR)], [enable PHP 5.x extension])
AC_HELP_STRING([--disable-php5], [disable PHP 5.x extension (default)])dnl
], [
     case "${enableval}" in
       yes)	with_php5="yes" ;;
       no)	with_php5="no" ;;
       /*)	with_php5="${enableval}" ;;
       *)	AC_MSG_ERROR(bad value ${enableval} for --enable-php5) ;;
     esac
  ],
  [ with_php5="no" ]
)

if test "x$with_php5" != "xno"
then
    AC_MSG_CHECKING([libphp5 library usability])
    save_CPPFLAGS="$CPPFLAGS"
    save_LIBS="$LIBS"
    old_LD_LIBRARY_PATH="$LD_LIBRARY_PATH"
    case "$with_php5" in
	yes)
	   php5_CFLAGS="-lphp5"
	   php5_LDFLAGS="-lphp5"
	   ;;
	*)
	   php5_CFLAGS="-I$with_php5/include/php/main -I$with_php5/include/php/Zend -I$with_php5/include/php/TSRM -I$with_php5/include/php"
	   php5_LDFLAGS="-L$with_php5/lib -lphp5"
	   LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$with_php5/lib"
	   export LD_LIBRARY_PATH
	   ;;
    esac
    LIBS="$LIBS $php5_LDFLAGS"
    CPPFLAGS="$CPPFLAGS $php5_CFLAGS"
    AC_TRY_RUN([
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <php.h>
int
main ()
{
  return 0;
}],
[
 AC_MSG_RESULT(good)
 BUILD_OPTS="$BUILD_OPTS php5"
 AC_DEFINE(_PHP, 1, [PHP])
 with_php5="yes"
],
[
 AC_MSG_RESULT([bad. Check config.log for details])
 with_php5="no"
])
    LIBS="$save_LIBS"
    CPPFLAGS="$save_CPPFLAGS"
    LD_LIBRARY_PATH="$old_LD_LIBRARY_PATH"
    export LD_LIBRARY_PATH
fi
AM_CONDITIONAL(HAVE_PHP5, test "x$with_php5" != "xno" )
AC_SUBST(php5_CFLAGS)
AC_SUBST(php5_LDFLAGS)


##########################################################################
##									##
##  Check for XML2 library functions					##
##									##
##########################################################################

AM_PATH_XML2(2.4.0)


##########################################################################
#                                                                        #
# Mono .NET Hosting                                                      #
#                                                                        #
##########################################################################
AC_ARG_ENABLE(mono, [dnl
AC_HELP_STRING([--enable-mono], [enable Mono extension])
AC_HELP_STRING([--disable-mono], [disable Mono extension (default)])dnl
], [
     case "${enableval}" in
       yes)	have_mono="yes" ;;
       no)	have_mono="no" ;;
       *)	AC_MSG_ERROR(bad value ${enableval} for --disable-mono) ;;
     esac
  ],
  [ have_mono="no" ]
)

if test "x$have_mono" = "xyes"
then
    BUILD_OPTS="$BUILD_OPTS mono"
    AC_PATH_PROG(WGET,wget)
fi

AM_CONDITIONAL(HAVE_MONO, test "x$have_mono" = "xyes")


##########################################################################
#                                                                        #
# Mono C# Compiler                                                       #
#                                                                        #
##########################################################################
AC_CHECK_PROGS(MCS, mcs gmcs csc, notfound)
AM_CONDITIONAL(HAVE_MCS, test "x$MCS" != "xnotfound")


##########################################################################
#                                                                        #
# Proj4 								 #
#                                                                        #
##########################################################################
AC_ARG_ENABLE(proj4, [dnl
AC_HELP_STRING([--enable-proj4(=DIR)], [enable the proj4 plugin (default)])
AC_HELP_STRING([--disable-proj4], [disable the proj4 plugin])dnl
], [
     case "${enableval}" in
       yes)	with_proj4="yes" ;;
       no)	with_proj4="no" ;;
       /*)	with_proj4="${enableval}" ;;
       *)	AC_MSG_ERROR(bad value ${enableval} for --enable-proj4) ;;
     esac
  ],
  [ with_proj4="yes" ]
)

if test "x$with_proj4" != "xno"
then
    AC_MSG_CHECKING([proj4 library usability])

    save_CPPFLAGS="$CPPFLAGS"
    save_LIBS="$LIBS"
    save_LD_LIBRARY_PATH="$LD_LIBRARY_PATH"

    if test "x$with_proj4" = "xyes"
    then
	PROJ4_CPPFLAGS=""
	PROJ4_LDFLAGS=""
    else
        PROJ4_CPPFLAGS="-I$with_proj4/include"
        PROJ4_LDFLAGS="-L$with_proj4/lib"
    fi
    PROJ4_LIBS="-lproj"

    CPPFLAGS="$CPPFLAGS $PROJ4_CPPFLAGS"
    LIBS="$LIBS $PROJ4_LDFLAGS $PROJ4_LIBS -lpthread -lm"

    LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$with_proj4/lib"
    export LD_LIBRARY_PATH

    AC_TRY_RUN([
#include <stdio.h>
#include <stdlib.h>
#include <proj_api.h>
int
main ()
{
  projPJ pj_merc;

  if (!(pj_merc = pj_init_plus("+proj=merc +ellps=clrk66 +lat_ts=33")) )
  exit(1);

  exit (0);
}],
[
  BUILD_OPTS="$BUILD_OPTS proj"
  AC_MSG_RESULT(good)
],
[
  AC_MSG_RESULT([bad. Check config.log for details])
  with_proj4="no"
  AC_MSG_WARN([The proj4 plugin will not be built])
])

    LIBS="$save_LIBS"
    CPPFLAGS="$save_CPPFLAGS"
    LD_LIBRARY_PATH="$save_LD_LIBRARY_PATH"
fi

AM_CONDITIONAL(WITH_PROJ4, test "x$with_proj4" != "xno" )
AC_SUBST(PROJ4_CPPFLAGS)
AC_SUBST(PROJ4_LDFLAGS)
AC_SUBST(PROJ4_LIBS)


##########################################################################
#                                                                        #
# Geos  								 #
#                                                                        #
##########################################################################
AC_ARG_ENABLE(geos, [dnl
AC_HELP_STRING([--enable-geos(=DIR)], [enable the geos plugin (default)])
AC_HELP_STRING([--disable-geos], [disable the geos plugin])dnl
], [
     case "${enableval}" in
       yes)	with_geos="yes" ;;
       no)	with_geos="no" ;;
       /*)	with_geos="${enableval}" ;;
       *)	AC_MSG_ERROR(bad value ${enableval} for --enable-geos) ;;
     esac
  ],
  [ with_geos="yes" ]
)

if test "x$with_geos" != "xno"
then
    AC_MSG_CHECKING([geos library usability])

    save_CPPFLAGS="$CPPFLAGS"
    save_LIBS="$LIBS"
    save_LD_LIBRARY_PATH="$LD_LIBRARY_PATH"

    if test "x$with_geos" = "xyes"
    then
	GEOS_CPPFLAGS=""
	GEOS_LDFLAGS=""
    else
        GEOS_CPPFLAGS="-I$with_geos/include"
        GEOS_LDFLAGS="-L$with_geos/lib"
    fi
    GEOS_LIBS="-lgeos"

    CPPFLAGS="$CPPFLAGS $GEOS_CPPFLAGS"
    LIBS="$LIBS $GEOS_LDFLAGS -lgeos_c -lgeos -lstdc++ -lm"

    LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$with_geos/lib"
    export LD_LIBRARY_PATH

    AC_TRY_RUN([
#include <stdio.h>
#include <stdlib.h>
#include <geos_c.h>
int
main ()
{
  GEOSWKBReader GEOS_DLL *reader;

  initGEOS(NULL, NULL);

  reader = GEOSWKBReader_create();
  if (!reader)
    exit (1);

  exit (0);
}],
[
  BUILD_OPTS="$BUILD_OPTS geos"
  AC_MSG_RESULT(good)
],
[
  AC_MSG_RESULT([bad. Check config.log for details])
  with_geos="no"
  AC_MSG_WARN([The geos plugin will not be built])
])

    LIBS="$save_LIBS"
    CPPFLAGS="$save_CPPFLAGS"
    LD_LIBRARY_PATH="$save_LD_LIBRARY_PATH"
fi

AM_CONDITIONAL(WITH_GEOS, test "x$with_geos" != "xno" )
AC_SUBST(GEOS_CPPFLAGS)
AC_SUBST(GEOS_LDFLAGS)
AC_SUBST(GEOS_LIBS)


##########################################################################
#                                                                        #
# shapefileio  								 #
#                                                                        #
##########################################################################
AC_ARG_ENABLE(shapefileio, [dnl
AC_HELP_STRING([--enable-shapefileio(=DIR)], [enable the shapefileio plugin (default)])
AC_HELP_STRING([--disable-shapefileio], [disable the shapefileio plugin])dnl
], [
     case "${enableval}" in
       yes)	with_shapefileio="yes" ;;
       no)	with_shapefileio="no" ;;
       /*)	with_shapefileio="${enableval}" ;;
       *)	AC_MSG_ERROR(bad value ${enableval} for --enable-shapefileio) ;;
     esac
  ],
  [ with_shapefileio="yes" ]
)

if test "x$with_shapefileio" != "xno"
then
    AC_MSG_CHECKING([shapefileio library usability])

    save_CPPFLAGS="$CPPFLAGS"
    save_LIBS="$LIBS"
    save_LD_LIBRARY_PATH="$LD_LIBRARY_PATH"

    if test "x$with_shapefileio" = "xyes"
    then
	SHAPEFILEIO_CPPFLAGS=""
	SHAPEFILEIO_LDFLAGS=""
    else
        SHAPEFILEIO_CPPFLAGS="-I$with_shapefileio/include"
        SHAPEFILEIO_LDFLAGS="-L$with_shapefileio/lib"
    fi
    SHAPEFILEIO_LIBS="-lshapefileio"

    CPPFLAGS="$CPPFLAGS $SHAPEFILEIO_CPPFLAGS"
    LIBS="$LIBS $SHAPEFILEIO_LDFLAGS -lshapefileio_c -lshapefileio -lc++"

    LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$with_shapefileio/lib"
    export LD_LIBRARY_PATH

    BUILD_OPTS="$BUILD_OPTS shapefileio"
    AC_MSG_RESULT(using internal library)

    LIBS="$save_LIBS"
    CPPFLAGS="$save_CPPFLAGS"
    LD_LIBRARY_PATH="$save_LD_LIBRARY_PATH"
fi

AM_CONDITIONAL(WITH_SHAPEFILEIO, test "x$with_shapefileio" != "xno" )
AC_SUBST(SHAPEFILEIO_CPPFLAGS)
AC_SUBST(SHAPEFILEIO_LDFLAGS)
AC_SUBST(SHAPEFILEIO_LIBS)


##########################################################################
#                                                                        #
# graphql  								 #
#                                                                        #
##########################################################################
AC_ARG_ENABLE(graphql, [dnl
AC_HELP_STRING([--enable-graphql(=DIR)], [enable the graphql plugin (default)])
AC_HELP_STRING([--disable-graphql], [disable the graphql plugin])dnl
], [
     case "${enableval}" in
       yes)	with_graphql="yes" ;;
       no)	with_graphql="no" ;;
       /*)	with_graphql="${enableval}" ;;
       *)	AC_MSG_ERROR(bad value ${enableval} for --enable-graphql) ;;
     esac
  ],
  [ with_graphql="yes" ]
)

AM_CONDITIONAL(WITH_GRAPHQL, test "x$with_graphql" != "xno" )
AC_SUBST(GRAPHQL_CPPFLAGS)
AC_SUBST(GRAPHQL_LDFLAGS)
AC_SUBST(GRAPHQL_LIBS)


##########################################################################
#                                                                        #
# HSLookup								 #
#                                                                        #
##########################################################################
AC_ARG_ENABLE(hslookup, [dnl
AC_HELP_STRING([--enable-hslookup(=DIR)], [enable the hslookup plugin (default)])
AC_HELP_STRING([--disable-hslookup], [disable the hslookup plugin])dnl
], [
     case "${enableval}" in
       yes)	with_hsl="yes" ;;
       no)	with_hsl="no" ;;
       /*)	with_hsl="${enableval}" ;;
       *)	AC_MSG_ERROR(bad value ${enableval} for --disable-hslookup) ;;
     esac
  ],
  [ with_hsl="yes" ]
)

if test "x$with_hsl" != "xno"
then
    AC_PATH_PROG(HS_LOOKUP, hslookup, notfound, ["$with_hsl/bin:$PATH"])

    if test "x$HS_LOOKUP" = "xnotfound"
    then
       AC_MSG_WARN([The hslookup plugin will not be built])
       with_hsl=no
    fi
fi

if test "x$with_hsl" != "xno"
then
    AC_MSG_CHECKING([hslookup library usability])

    save_CPPFLAGS="$CPPFLAGS"
    save_LIBS="$LIBS"
    save_LD_LIBRARY_PATH="$LD_LIBRARY_PATH"

    if test "x$with_hsl" = "xyes"
    then
	HSL_CPPFLAGS=""
	HSL_LDFLAGS=""
    else
        HSL_CPPFLAGS="-I$with_hsl/include"
        HSL_LDFLAGS="-L$with_hsl/lib"
    fi
    HSL_LIBS="-lhdl"

    CPPFLAGS="$CPPFLAGS $HSL_CPPFLAGS"
    LIBS="$LIBS $HSL_LDFLAGS $HSL_LIBS"

    LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$with_hsl/lib"
    export LD_LIBRARY_PATH

    AC_TRY_RUN([
#include <stdio.h>
#include <stdlib.h>
#include <hdl/hdl.h>
int
main ()
{
  HDLContext *ctx;
  ctx = HDLInitResolver();
  if (ctx)
    exit (0);

  exit (1);
}],
[
  BUILD_OPTS="$BUILD_OPTS hslookup"
  AC_MSG_RESULT(good)
],
[
  AC_MSG_RESULT([bad. Check config.log for details])
  with_hsl="no"
  AC_MSG_WARN([The hslookup plugin will not be built])
])

    LIBS="$save_LIBS"
    CPPFLAGS="$save_CPPFLAGS"
    LD_LIBRARY_PATH="$save_LD_LIBRARY_PATH"
fi

AM_CONDITIONAL(WITH_HSL, test "x$with_hsl" != "xno" )
AC_SUBST(HSL_CPPFLAGS)
AC_SUBST(HSL_LDFLAGS)
AC_SUBST(HSL_LIBS)


##########################################################################
#                                                                        #
# ImageMagic                                                             #
#                                                                        #
##########################################################################

AC_ARG_ENABLE(imagemagick, [dnl
AC_HELP_STRING([--enable-imagemagick(=DIR)], [enable the ImageMagick plugin (default)])
AC_HELP_STRING([--disable-imagemagick], [disable the ImageMagick plugin])dnl
], [
     case "${enableval}" in
       yes)	with_im="yes" ;;
       no)	with_im="no" ;;
       /*)	with_im="${enableval}"
		PKG_CONFIG_PATH="${enableval}/lib/pkgconfig:$PKG_CONFIG_PATH"
		export PKG_CONFIG_PATH
		;;
       *)	AC_MSG_ERROR(bad value ${enableval} for --disable-imagemagick) ;;
     esac
  ],
  [ with_im="yes" ]
)

PKG_CHECK_MODULES_STATIC(IM, MagickWand, [], [
    AC_PATH_PROG(IM_CONFIG, Wand-config, notfound, ["$with_im/bin:$PATH"])
    if test "x$IM_CONFIG" != "xnotfound"
    then
	IM_CFLAGS=`"$IM_CONFIG" --cflags`
	IM_LIBS=`"$IM_CONFIG" --libs --static`
    else
	AC_MSG_WARN([The ImageMagick plugin will not be built])
	with_im=no
    fi
])

if test "x$with_im" != "xno"
then
    AC_MSG_CHECKING([ImageMagick library usability])

    save_CFLAGS="$CFLAGS"
    save_LIBS="$LIBS"
    save_LD_LIBRARY_PATH="$LD_LIBRARY_PATH"

    CFLAGS="$CFLAGS $IM_CFLAGS"
    LIBS="$LIBS $IM_LIBS -lpthread"

    LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$with_im/lib"
    export LD_LIBRARY_PATH

    AC_TRY_RUN([
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <wand/magick-wand.h>
MagickWand *magick_wand;
int
main ()
{
  MagickWandGenesis();
  return 0;
}],
[
  BUILD_OPTS="$BUILD_OPTS im"
  AC_MSG_RESULT(good)
],
[
  AC_MSG_RESULT([bad. Check config.log for details])
  with_im="no"
  AC_MSG_WARN([The ImageMagick plugin will not be built])
])

    LIBS="$save_LIBS"
    CFLAGS="$save_CFLAGS"
    LD_LIBRARY_PATH="$save_LD_LIBRARY_PATH"
fi

AM_CONDITIONAL(WITH_IM, test "x$with_im" != "xno" )
AC_SUBST(IM_CFLAGS)
AC_SUBST(IM_LIBS)


##########################################################################
#                                                                        #
# WbXML2                                                                 #
#                                                                        #
##########################################################################
AC_ARG_ENABLE(wbxml2, [dnl
AC_HELP_STRING([--enable-wbxml2(=DIR)], [enable the WBXML2 plugin (default)])
AC_HELP_STRING([--disable-wbxml2], [disable the WBXML2 plugin])dnl
], [
     case "${enableval}" in
       yes)	with_wbxml2="yes" ;;
       no)	with_wbxml2="no" ;;
       /*)	with_wbxml2="${enableval}" ;;
       *)	AC_MSG_ERROR(bad value ${enableval} for --disable-wbxml2) ;;
     esac
  ],
  [ with_wbxml2="yes" ]
)

if test "x$with_wbxml2" != "xno"
then
    AC_MSG_CHECKING([WBXML2 library usability])
    old_CFLAGS="$CFLAGS"
    save_LIBS="$LIBS"
    old_LD_LIBRARY_PATH="$LD_LIBRARY_PATH"
    case "$with_wbxml2" in
	yes)
	   WBXML2_CFLAGS=""
	   WBXML2_LDFLAGS="-lwbxml2"
	   ;;
	*)
	   WBXML2_CFLAGS="-I$with_wbxml2/include"
	   WBXML2_LDFLAGS="-L$with_wbxml2/lib -lwbxml2"
	   LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$with_wbxml2/lib"
	   export LD_LIBRARY_PATH
	   ;;
    esac

    CFLAGS="$CFLAGS $WBXML2_CFLAGS"
    LIBS="$LIBS $WBXML2_LDFLAGS"

    AC_TRY_RUN([
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <wbxml.h>
int
main ()
{
  WBXMLParser *wbxml_parser = wbxml_parser_create();

  return 0;
}],
[
 BUILD_OPTS="$BUILD_OPTS wbxml2"
 AC_MSG_RESULT(good)
],
[
 AC_MSG_RESULT([bad. Check config.log for details])
 with_wbxml2="no"
])
    CFLAGS="$old_CFLAGS"
    LIBS="$save_LIBS"
    LD_LIBRARY_PATH="$old_LD_LIBRARY_PATH"
    export LD_LIBRARY_PATH
fi
AM_CONDITIONAL(WITH_WBXML2, test "x$with_wbxml2" != "xno" )
AC_SUBST(WBXML2_CFLAGS)
AC_SUBST(WBXML2_LDFLAGS)


##########################################################################
#                                                                        #
# Perl Hosting                                                           #
#                                                                        #
##########################################################################
with_perl="no"
AC_ARG_ENABLE(perl, [dnl
AC_HELP_STRING([--enable-perl], [enable PERL hosting])
AC_HELP_STRING([--disable-perl], [disable PERL hosting (default)])dnl
], [
     case "${enableval}" in
       yes)	with_perl="yes" ;;
       no)	with_perl="no" ;;
       *)	AC_MSG_ERROR(bad value ${enableval} for --enable-perl) ;;
     esac
  ],
  [ with_perl="no" ]
)

AM_CONDITIONAL(WITH_PERL, test "x$PERL" != "x" -a "x$with_perl" != "xno")
if test "x$PERL" != "x" -a "x$with_perl" != "xno" ; then
     PERL_LDFLAGS=`$PERL -MExtUtils::Embed -e ldopts`
     PERL_CFLAGS=`$PERL -MExtUtils::Embed -e ccopts`
fi
AC_SUBST(PERL_CFLAGS)
AC_SUBST(PERL_LDFLAGS)


##########################################################################
#                                                                        #
# Python Hosting                                                         #
#                                                                        #
##########################################################################
with_python="no"
AC_ARG_ENABLE(python, [dnl
AC_HELP_STRING([--enable-python], [enable PYTHON hosting])
AC_HELP_STRING([--disable-python], [disable PYTHON hosting (default)])dnl
], [
     case "${enableval}" in
       yes)	with_python="yes";;
       no)	with_python="no";;
       *)	AC_MSG_ERROR(bad value ${enableval} for --enable-python) ;;
     esac
  ],
  [ with_python="no" ]
)

AM_CONDITIONAL(WITH_PYTHON, test "x$PYTHON" != "x" -a "x$with_python" != "xno")
if test "x$PYTHON" != "x"  -a "x$with_python" != "xno" ; then
    PYLIBS=`$PYTHON -c 'import distutils.sysconfig; print distutils.sysconfig.get_config_var ("LIBS");'`
    PYSYSLIBS=`$PYTHON -c 'import distutils.sysconfig; print distutils.sysconfig.get_config_var ("SYSLIBS");'`
    PYLDFLAGS=`$PYTHON -c 'import distutils.sysconfig; print distutils.sysconfig.get_config_var ("LDFLAGS");'`
    PYLIBPL=`$PYTHON -c 'import distutils.sysconfig; print distutils.sysconfig.get_config_var ("LIBPL");'`
    PYVERSION=`$PYTHON -c 'import distutils.sysconfig; print distutils.sysconfig.get_config_var ("VERSION");'`
    PYINC=`$PYTHON -c 'import distutils.sysconfig; print distutils.sysconfig.get_config_var ("INCLUDEPY");'`
    PYCFLAGS=`$PYTHON -c 'import distutils.sysconfig; print distutils.sysconfig.get_config_var ("CFLAGS");'`
    PYSO=`$PYTHON -c 'import distutils.sysconfig; print distutils.sysconfig.get_config_var ("SO");'`
    LIBPYTHON_SO="libpython$PYVERSION$PYSO"
    PYTHON_CFLAGS="-I$PYINC $PYCFLAGS -DLIBPYTHON_SO=\"$LIBPYTHON_SO\" $PY_ARCH_CFLAGS"
    PYTHON_LDFLAGS="$PYLIBS $PYSYSLIBS $PYLDFLAGS -L$PYLIBPL -lpython$PYVERSION $PY_ARCH_LDFLAGS"
fi
AC_SUBST(PYTHON_CFLAGS)
AC_SUBST(PYTHON_LDFLAGS)


##########################################################################
#                                                                        #
# Ruby Hosting                                                           #
#                                                                        #
##########################################################################
with_ruby="no"
AC_ARG_ENABLE(ruby, [dnl
AC_HELP_STRING([--enable-ruby], [enable RUBY hosting])
AC_HELP_STRING([--disable-ruby], [disable RUBY hosting (default)])dnl
], [
     case "${enableval}" in
       yes)	with_ruby="yes";;
       no)	with_ruby="no";;
       *)	AC_MSG_ERROR(bad value ${enableval} for --enable-ruby) ;;
     esac
  ],
  [ with_ruby="no" ]
)

if test "x$RUBY" != "x"  -a "x$with_ruby" != "xno" ; then
    RUBY_ARCHDIR=`$RUBY -e 'require "rbconfig.rb"; puts Config::expand("\$(archdir)")'`
    RUBY_CFLAGS="-I$RUBY_ARCHDIR"
    RUBY_LDFLAGS="-lruby"
    save_CPPFLAGS="$CPPFLAGS"
    save_LIBS="$LIBS"
    CPPFLAGS="$CPPFLAGS $RUBY_CFLAGS"
    LIBS="$LIBS $RUBY_LDFLAGS"

    AC_MSG_CHECKING([Ruby library usability])
    AC_TRY_RUN([
#include <stdio.h>
#include <stdlib.h>
#include "ruby.h"
int
main ()
{
  ruby_init ();
  return 0;
}],
[
 AC_MSG_RESULT(good)
],
[
 AC_MSG_RESULT([bad. Check config.log for details])
 with_ruby="no"
])

    LIBS="$save_LIBS"
    CPPFLAGS="$save_CPPFLAGS"
fi
AM_CONDITIONAL(WITH_RUBY, test "x$RUBY" != "x" -a "x$with_ruby" != "xno")
AC_SUBST(RUBY_CFLAGS)
AC_SUBST(RUBY_LDFLAGS)


##########################################################################
##									##
##  Check out system zlib library					##
##									##
##########################################################################
with_zlib="no"
AC_ARG_WITH(internal-zlib, [dnl
AC_HELP_STRING([--with-internal-zlib], [use internal zlib library (default)])
AC_HELP_STRING([--without-internal-zlib], [use external zlib support])dnl
], [
     case "${withval}" in
       yes)	with_zlib="internal";;
       no)	with_zlib="external";;
       *)	AC_MSG_ERROR(bad value ${withval} for --enable-zlib) ;;
     esac
  ],
  [ with_zlib="internal" ]
)

if test "x$with_zlib" != "xinternal"
then
    AC_CHECK_HEADER(zlib.h)
    AC_CHECK_LIB(z, main, [with_zlib=yes], [with_zlib=internal])
fi
if test "x$with_zlib" = "xinternal"
then
    ZLIB_INC='-I$(top_srcdir)/libsrc/zlib'
    ZLIB_LIB='$(top_builddir)/libsrc/zlib/libz.la'
else
    ZLIB_INC=""
    ZLIB_LIB="-lz"
fi
AC_SUBST(ZLIB_INC)
AC_SUBST(ZLIB_LIB)

AM_CONDITIONAL(WITH_ZLIB, test "x$with_zlib" = "xinternal")


##########################################################################
##									##
##  Check out system lzma library					##
##									##
##########################################################################
AC_ARG_ENABLE(lzma, [dnl
AC_HELP_STRING([--enable-lzma(=DIR)], [enable the lzma decompressor (default)])
AC_HELP_STRING([--disable-lzma], [disable the lzma decompressor LZMA])dnl
], [
     case "${enableval}" in
       yes)	with_lzma="yes" ;;
       no)	with_lzma="no" ;;
       /*)	with_lzma="${enableval}" ;;
       *)	AC_MSG_ERROR(bad value ${enableval} for --disable-lzma) ;;
     esac
  ],
  [ with_lzma="yes" ]
)

if test "x$with_lzma" != "xno"
then
    AC_MSG_CHECKING([LZMA library usability])
    old_CFLAGS="$CFLAGS"
    save_LIBS="$LIBS"
    old_LD_LIBRARY_PATH="$LD_LIBRARY_PATH"
    case "$with_lzma" in
	yes)
	   LZMA_CFLAGS=""
	   LZMA_LDFLAGS="-llzma"
	   ;;
	*)
	   LZMA_CFLAGS="-I$with_lzma/include"
	   LZMA_LDFLAGS="-L$with_lzma/lib -llzma -lpthread"
	   LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$with_lzma/lib"
	   export LD_LIBRARY_PATH
	   ;;
    esac

    CFLAGS="$CFLAGS $LZMA_CFLAGS"
    LIBS="$LIBS $LZMA_LDFLAGS"

    AC_TRY_RUN([
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <lzma.h>
int
main ()
{
  lzma_stream strm = LZMA_STREAM_INIT;
  lzma_ret ret = lzma_stream_decoder(&strm, UINT64_MAX, LZMA_CONCATENATED); 

  if (ret == LZMA_OK)
    return 0;

  return -1;
}],
[
 AC_MSG_RESULT(good)
 srvrlibs="$srvrlibs $LZMA_LDFLAGS"
 INCL="$INCL $LZMA_CFLAGS"
 AC_DEFINE(HAVE_LZMA, 1, [LZMA support])
 BUILD_OPTS="$BUILD_OPTS lzma"
],
[
 AC_MSG_RESULT([bad. Check config.log for details])
 with_lzma="no"
])
    CFLAGS="$old_CFLAGS"
    LIBS="$save_LIBS"
    LD_LIBRARY_PATH="$old_LD_LIBRARY_PATH"
    export LD_LIBRARY_PATH
fi
AC_SUBST(LZMA_CFLAGS)
AC_SUBST(LZMA_LDFLAGS)


##########################################################################
##									##
##  Check out system bz2 library					##
##									##
##########################################################################
AC_ARG_ENABLE(bz2, [dnl
AC_HELP_STRING([--enable-bz2(=DIR)], [enable the bz2 decompressor (default)])
AC_HELP_STRING([--disable-bz2], [disable the bz2 decompressor ])dnl
], [
     case "${enableval}" in
       yes)	with_bz2="yes" ;;
       no)	with_bz2="no" ;;
       /*)	with_bz2="${enableval}" ;;
       *)	AC_MSG_ERROR(bad value ${enableval} for --disable-bz2) ;;
     esac
  ],
  [ with_bz2="yes" ]
)

if test "x$with_bz2" != "xno"
then
    AC_MSG_CHECKING([BZ2 library usability])
    old_CFLAGS="$CFLAGS"
    save_LIBS="$LIBS"
    old_LD_LIBRARY_PATH="$LD_LIBRARY_PATH"
    case "$with_bz2" in
	yes)
	   BZ2_CFLAGS=""
	   BZ2_LDFLAGS="-lbz2"
	   ;;
	*)
	   BZ2_CFLAGS="-I$with_bz2/include"
	   BZ2_LDFLAGS="-L$with_bz2/lib -lbz2"
	   LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$with_bz2/lib"
	   export LD_LIBRARY_PATH
	   ;;
    esac

    CFLAGS="$CFLAGS $BZ2_CFLAGS"
    LIBS="$LIBS $BZ2_LDFLAGS"

    AC_TRY_RUN([
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <bzlib.h>
int
main ()
{
  bz_stream strm = {0};
  int ret = BZ2_bzDecompressInit(&strm, 0, 0) != BZ_OK;
  if (ret == BZ_OK)
    return 0;
  return -1;
}],
[
 AC_MSG_RESULT(good)
 srvrlibs="$srvrlibs $BZ2_LDFLAGS"
 INCL="$INCL $BZ2_CFLAGS"
 AC_DEFINE(HAVE_BZ2, 1, [BZ2 support])
 BUILD_OPTS="$BUILD_OPTS bz2"
],
[
 AC_MSG_RESULT([bad. Check config.log for details])
 with_bz2="no"
])
    CFLAGS="$old_CFLAGS"
    LIBS="$save_LIBS"
    LD_LIBRARY_PATH="$old_LD_LIBRARY_PATH"
    export LD_LIBRARY_PATH
fi
AC_SUBST(BZIP2_CFLAGS)
AC_SUBST(BZIP2_LDFLAGS)

dnl PUT OTHER EXTENSIONS HERE


##########################################################################
##									##
##  Check out system malloc library					##
##									##
##########################################################################

AC_ARG_WITH(malloc-debug, [dnl
AC_HELP_STRING([--with-malloc-debug], [extra malloc debugging code])],
    [ with_malloc_debug="$withval" ],
    [ with_malloc_debug="no" ]
)

if test "x$with_malloc_debug" = "xyes"; then
    BUILD_OPTS="$BUILD_OPTS malloc_debug"
    CCDEBUG="$CCDEBUG -DMALLOC_DEBUG"
    CCOPT="-g"
    AM_LDFLAGS="-g"
fi


AC_ARG_WITH(mtx-debug, [dnl
AC_HELP_STRING([--with-mtx-debug], [extra mutex debugging code])],
    [ with_mtx_debug="$withval" ],
    [ with_mtx_debug="no" ]
)

if test "x$with_mtx_debug" = "xyes"; then
    BUILD_OPTS="$BUILD_OPTS mtx_debug"
    CCDEBUG="$CCDEBUG -DMTX_DEBUG"
    CCOPT="-g"
    AM_LDFLAGS="-g"
fi


##########################################################################
##									##
##  Check out POSIX threads libs    					##
##									##
##########################################################################

AC_ARG_WITH(pthreads, [dnl
AC_HELP_STRING([--with-pthreads], [build pthread implementation if possible])],
    [ with_pthreads="$withval" ],
    [ with_pthreads="yes" ]
)

if test $with_pthreads = "yes"; then
    AC_CHECK_LIB(pthreads, pthread_create,
       [BUILD_OPTS="$BUILD_OPTS pthreads"
	WITH_PTHREADS="yes"
	if test "$host_os" = "osf3.2"
	then
	  BUILD_OPTS="$BUILD_OPTS old_pthreads"
	  LIBTHR="-lpthreads -lmach -lc_r"
	  AC_DEFINE([OLD_PTHREADS], [1], [Old pthreads])
	else
	  LIBTHR="-lpthreads"
	fi
	AC_DEFINE([_REENTRANT], [1], [use reentrant code])
	AC_DEFINE([WITH_PTHREADS],
		  [1],
		  [pthreads] )
	],
       [AC_CHECK_LIB(pthread, pthread_create,
         [BUILD_OPTS="$BUILD_OPTS pthreads"
	  WITH_PTHREADS="yes"
	  LIBTHR="-lpthread"
	  AC_DEFINE([_REENTRANT], [1], [use reentrant code])
	  AC_DEFINE([WITH_PTHREADS],
	            [1],
		    [pthreads] )])])
fi
if test "x$have_mono" = "xyes" ; then
    AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
    if test "x$PKG_CONFIG" = "xno"; then
	AC_MSG_ERROR([You need to install pkg-config])
    fi

    BUILD_GLIB_CFLAGS=`$PKG_CONFIG --cflags glib-2.0 gthread-2.0`
    BUILD_GLIB_LIBS=`$PKG_CONFIG --libs glib-2.0 gthread-2.0`
    AC_SUBST(BUILD_GLIB_CFLAGS)
    AC_SUBST(BUILD_GLIB_LIBS)

    pkg_config_path=
    AC_ARG_WITH(crosspkgdir, [  --with-crosspkgdir=/path/to/pkg-config/dir],
	if test x$with_crosspkgdir = "x"; then
		if test -s $PKG_CONFIG_PATH; then
			pkg_config_path=$PKG_CONFIG_PATH
		fi
	else
		pkg_config_path=$with_crosspkgdir
		PKG_CONFIG_PATH=$pkg_config_path
		export PKG_CONFIG_PATH
	fi
    )

## Versions of dependencies
    GLIB_REQUIRED_VERSION=1.3.11

    $PKG_CONFIG --atleast-version=$GLIB_REQUIRED_VERSION glib-2.0
    if test $? -gt 0 ; then
	AC_MSG_ERROR([You need to install glib-2.0 version $GLIB_REQUIRED_VERSION or greater])
    fi
#    PKG_CHECK_MODULES_(BASE_DEPENDENCIES, glib-2.0 >= $GLIB_REQUIRED_VERSION)

    GLIB_CFLAGS=`$PKG_CONFIG --cflags glib-2.0 gthread-2.0`
    GLIB_LIBS=`$PKG_CONFIG --libs glib-2.0 gthread-2.0`
    GMODULE_CFLAGS=`$PKG_CONFIG --cflags gmodule-2.0`
    GMODULE_LIBS=`$PKG_CONFIG --libs gmodule-2.0`

    AC_SUBST(GLIB_CFLAGS)
    AC_SUBST(GLIB_LIBS)
    AC_SUBST(GMODULE_CFLAGS)
    AC_SUBST(GMODULE_LIBS)
fi
AC_SUBST(LIBTHR)
save_LIBS="$LIBS"
LIBS="$LIBTHR $LIBS"
AC_CHECK_FUNCS(pthread_attr_setstacksize pthread_attr_getstacksize pthread_sigmask pthread_rwlock_init)
LIBS="$save_LIBS"
srvrlibs="$srvrlibs $LIBTHR"
AM_CONDITIONAL(WITH_PTHREADS, test "x$WITH_PTHREADS" = "xyes" )


##########################################################################
#                                                                        #
# AIO                                                                    #
#                                                                        #
##########################################################################
AC_ARG_ENABLE(aio, [dnl
AC_HELP_STRING([--enable-aio], [enable AIO support])
AC_HELP_STRING([--disable-aio], [disable AIO support (default)])dnl
], [
     case "${enableval}" in
       yes)	with_aio="yes" ;;
       no)	with_aio="no" ;;
       *)	AC_MSG_ERROR(bad value ${enableval} for --enable-aio) ;;
     esac
  ],
  [ with_aio="no" ]
)

if test "$with_aio" != "no"
then
   AIOLIB=""
   AC_CHECK_HEADERS(aio.h sched.h)
   AC_CHECK_LIB(rt, aio_read, [
	AIOLIB="-lrt" 
	AC_DEFINE(HAVE_AIO, 1, "Enable AIO support")
   ])
   srvrlibs="$srvrlibs $AIOLIB"
fi


##########################################################################
##									##
##  Check out additional libs 						##
##									##
##########################################################################

AC_MSG_CHECKING(for --with-libs)
AC_ARG_WITH(libs, [dnl
AC_HELP_STRING([--with-libs='lib1 ...'], [link against additional libs])dnl
], [
  AC_MSG_RESULT($withval)
  VLIBS="$withval $VLIBS"
], AC_MSG_RESULT(no))


##########################################################################
##									##
##  Check out editline / readline					##
##									##
##########################################################################

LIBRDL=""
RDLFLAGS=""
_save_LIBS=$LIBS

AC_MSG_CHECKING(for --with-editline)
AC_ARG_WITH(editline, [dnl
AC_HELP_STRING([--with-editline(=DIR)], [use editline library])dnl
], [
  AC_MSG_RESULT($withval)
  AC_DEFINE(WITH_EDITLINE, 1, [editline])
  if test -d "$withval/lib"
  then
      RDLFLAGS="-L$withval/lib"
  fi
  # first check if we can compile without lib termcap
  AC_MSG_CHECKING(for -ledit without -ltermcap)
  # check if libedit exists
  LIBS="$RDLFLAGS -ledit"
  AC_TRY_LINK(extern char *readline();,char *line=readline();,
  [
	BUILD_OPTS="$BUILD_OPTS editline"
	LIBRDL="$RDLFLAGS -ledit"
	AC_MSG_RESULT(yes)
  ], [
	AC_MSG_RESULT(no)
	AC_CHECKING(for -ledit that needs -ltermcap)
	termcap=
	AC_CHECK_LIB(ncurses, tgetent, [termcap=ncurses], [
	AC_CHECK_LIB(termlib, tgetent, [termcap=termlib], [
	AC_CHECK_LIB(termcap, tgetent, [termcap=termcap], [
	AC_CHECK_LIB(curses,  tgetent, [termcap=curses],  [
	AC_ERROR(no working -ltermcap/termlib found -- do not use --with-editline)])])])])
	LIBS="$LIBS -l$termcap"
	AC_MSG_CHECKING(for -ledit)
	AC_TRY_LINK(extern char *readline();, char *line=readline();,
	[
	   BUILD_OPTS="$BUILD_OPTS editline"
	   LIBRDL="$RDLFLAGS -ledit -l$termcap"
	   AC_MSG_RESULT(yes)
	], [
	   AC_ERROR(no working editline library found -- do not use --with-editline)
	])
  ])
  ], [
    AC_MSG_RESULT(no)
  ]
)


AC_MSG_CHECKING(for --with-readline)
AC_ARG_WITH(readline, [dnl
AC_HELP_STRING([--with-readline(=DIR)], [use GNU readline library])dnl
], [
  AC_MSG_RESULT($withval)
  AC_DEFINE(WITH_READLINE, 1, [readline])
  if test -d "$withval"
  then
      LDFLAGS="$LDFLAGS -L$withval"
  fi
  # first check if we can compile without lib termcap
  AC_MSG_CHECKING(for -lreadline without -ltermcap)
  # check if a libreadline exists
  LIBS="$LIBS -lreadline"
  AC_TRY_LINK(extern char *readline();,char *line=readline();,
  [
	BUILD_OPTS="$BUILD_OPTS readline"
	LIBRDL="-lreadline"
	AC_MSG_RESULT(yes)
  ], [
	AC_MSG_RESULT(no)
	AC_CHECKING(for -lreadline that needs -ltermcap)
	termcap=
	AC_CHECK_LIB(termcap, tgetent, [termcap=termcap], [
	AC_CHECK_LIB(termlib, tgetent, [termcap=termlib], [
	AC_CHECK_LIB(ncurses, tgetent, [termcap=ncurses], [
	AC_CHECK_LIB(curses,  tgetent, [termcap=curses], [
	AC_ERROR(no working -ltermcap/termlib found -- do not use --with-readline)])])])])
	LIBS="$LIBS -l$termcap"
	AC_MSG_CHECKING(for -lreadline)
	AC_TRY_LINK(extern char *readline();, char *line=readline();,[
	   BUILD_OPTS="$BUILD_OPTS readline"
	   LIBRDL="-lreadline -lhistory -l$termcap"
	   AC_MSG_RESULT(yes)], [
	   AC_ERROR(no working GNU readline library found -- do not use --with-readline)])
  ])
  ],[
    AC_MSG_RESULT(no)
  ]
)

LIBS=$_save_LIBS
AC_SUBST(LIBRDL)


##########################################################################
##                                                                      ##
##  Check for dynamic load module                                       ##
##                                                                      ##
##########################################################################

LIBDL=""
AC_CHECK_FUNC(dlopen,
  [LIBDL=""],
  [AC_CHECK_LIB(dl, dlopen, [LIBDL="-ldl"])]
)
AC_SUBST(LIBDL)
AC_CHECK_LIB(dl, dlopen, AC_DEFINE(HAVE_LIBDL, 1, [dlopen in -ldl]), ,)
AC_CHECK_LIB(dld, shl_load, AC_DEFINE(HAVE_SHL_LOAD, 1, [shl_load in dld]), ,)

srvrlibs="$srvrlibs $LIBDL"


##########################################################################
##									##
##  Check iodbc 							##
##									##
##########################################################################

AC_MSG_CHECKING(for iODBC location)
virt_iodbc_dir="."
virt_with_iodbc="no"
AC_ARG_WITH(iodbc, [dnl
AC_HELP_STRING([--with-iodbc(=DIR)], [build with iODBC implementation if possible])dnl
], [
      case "${withval}" in
	  yes)	virt_with_iodbc="yes" ;;
	  no)	virt_with_iodbc="no"  ;;
	  /*)	virt_with_iodbc="yes" virt_iodbc_dir="${withval}" ;;
	  *)	AC_MSG_ERROR("Invalid value for the --with-iodbc : must be an absolute path") ;;
      esac
    ],
    [ virt_with_iodbc="no" ])

AC_MSG_RESULT($virt_iodbc_dir)
AC_DEFINE(NO_UDBC_SDK,1, [Define if using the new iODBC API])


#
#  Check for installed versions of iODBC
#
if test "x$virt_with_iodbc" = "xyes"
then
    AC_CHECK_PROGS(IODBC_CONFIG, iodbc-config, false, [$virt_iodbc_dir/bin:$virt_iodbc_dir:$PATH])
    AC_CHECK_PROGS(PKG_CONFIG, pkg-config, false, [$virt_iodbc_dir/bin:$virt_iodbc_dir:$PATH])

    if "$IODBC_CONFIG" --version 2>/dev/null
    then
	iodbc_CFLAGS=`"$IODBC_CONFIG" --cflags`
	iodbc_LIBS=`"$IODBC_CONFIG" --libs`
    elif "$PKG_CONFIG" --version 2>/dev/null
    then
	saved_PKG_CONFIG_PATH="$PKG_CONFIG_PATH"
	PKG_CONFIG_PATH="$virt_iodbc_dir/lib/pkgconfig:$PKG_CONFIG_PATH"

	if "$PKG_CONFIG" --exists libiodbc
	then
	    iodbc_CFLAGS=`$PKG_CONFIG libiodbc --cflags`
	    iodbc_LIBS=`$PKG_CONFIG libiodbc --libs`
	fi

	PKG_CONFIG_PATH="$saved_PKG_CONFIG_PATH"
    elif test -d "$virt_iodbc_dir"
    then
	if test -d "$virt_iodbc_dir/include"
	then
	    iodbc_CFLAGS="$virt_iodbc_dir/include"
	fi
	if test -d "$virt_iodbc_dir/lib"
	then
	    iodbc_LIBS="-L$virt_iodbc_dir/lib -liodbc -liodbcinst"
	fi
    fi
fi


#
#  Only add path when using iODBC, otherwise the makefiles will
#  get the headers from libsrc/odbcsdk/include automatically
#
if test "x$virt_with_iodbc" = "xyes"
then
    saved_CPPFLAGS="$CPPFLAGS"
    CPPFLAGS="$iodbc_CFLAGS $CPPFLAGS"

    saved_LIBS="$LIBS"
    LIBS="$iodbc_LIBS $LIBS $DLLIB"

    AC_CHECK_HEADERS(sql.h sqlext.h sqlucode.h odbcinst.h)

    AC_MSG_CHECKING(iODBC libraries)
    AC_TRY_COMPILE([
	#include <sql.h>
	#include <sqlext.h>],[
	SQLRETURN ret;
	SQLHANDLE env_handle;
	ret = SQLAllocHandle ( SQL_HANDLE_ENV, SQL_NULL_HANDLE, &env_handle);
	],
	[
	    virt_with_iodbc=yes
	    AC_MSG_RESULT(done)
	],
	[
 	    virt_with_iodbc=no
	    AC_MSG_RESULT(failed)
        ]
    )

    CPPFLAGS="$saved_CPPFLAGS"
    LIBS="$saved_LIBS"
else
  #
  #  we have a copy of these files internally
  #
  AC_DEFINE(HAVE_SQL_H, 1)
  AC_DEFINE(HAVE_SQLEXT_H, 1)
  AC_DEFINE(HAVE_SQLUCODE_H, 1)
  AC_DEFINE(HAVE_ODBCINST_H, 1)

  iodbc_CFLAGS='-I$(top_srcdir)/libsrc/odbcsdk/include'
  iodbc_LIBS="-liodbc -liodbcinst"
fi

if test "x$virt_with_iodbc" = "xyes"
then
  BUILD_OPTS="$BUILD_OPTS odbc"
  AC_MSG_RESULT(Will build the iODBC binaries)
fi

AC_SUBST(iodbc_CFLAGS)
AC_SUBST(iodbc_LIBS)
AM_CONDITIONAL(WITH_IODBC, test "x$virt_with_iodbc" = "xyes" )


##########################################################################
##									##
##  Check for java 							##
##									##
##########################################################################

AC_MSG_CHECKING(for Java options)

ac_jdk4_path="none"
AC_ARG_WITH(jdk4, [dnl
AC_HELP_STRING([--with-jdk4=DIR], [use the Sun JDK 1.6.x at the specified location])dnl
], [
    case "${withval}" in
      yes)
          AC_MSG_ERROR("You need to specify a directory")
	  ;;

      no)
	  ac_jdk4_path="none"
	  ;;

      *)
	  if test -d "${withval}" ; then
	      ac_jdk4_path="${withval}"
	  else
	      AC_MSG_ERROR("Directory specified with --with-jdk4 does not exist")
	  fi
	  ;;
    esac
    ])
AC_MSG_RESULT(done)


ac_jdk4_1_path="none"
AC_ARG_WITH(jdk4_1, [dnl
AC_HELP_STRING([--with-jdk4_1=DIR], [use the Oracle JDK 1.7.x at the specified location])dnl
], [
    case "${withval}" in
      yes)
          AC_MSG_ERROR("You need to specify a directory")
	  ;;

      no)
	  ac_jdk4_1_path="none"
	  ;;

      *)
	  if test -d "${withval}" ; then
	      ac_jdk4_1_path="${withval}"
	  else
	      AC_MSG_ERROR("Directory specified with --with-jdk4_1 does not exist")
	  fi
	  ;;
    esac
    ])
AC_MSG_RESULT(done)

ac_jdk4_2_path="none"
AC_ARG_WITH(jdk4_2, [dnl
AC_HELP_STRING([--with-jdk4_2=DIR], [use the Oracle JDK 1.8.x at the specified location])dnl
], [
    case "${withval}" in
      yes)
          AC_MSG_ERROR("You need to specify a directory")
	  ;;

      no)
	  ac_jdk4_2_path="none"
	  ;;

      *)
	  if test -d "${withval}" ; then
	      ac_jdk4_2_path="${withval}"
	  else
	      AC_MSG_ERROR("Directory specified with --with-jdk4_2 does not exist")
	  fi
	  ;;
    esac
    ])
AC_MSG_RESULT(done)

ac_jdk4_3_path="none"
AC_ARG_WITH(jdk4_3, [dnl
AC_HELP_STRING([--with-jdk4_3=DIR], [use the Oracle JDK 9.x-14.x at the specified location])dnl
], [
    case "${withval}" in
      yes)
          AC_MSG_ERROR("You need to specify a directory")
	  ;;

      no)
	  ac_jdk4_3_path="none"
	  ;;

      *)
	  if test -d "${withval}" ; then
	      ac_jdk4_3_path="${withval}"
	  else
	      AC_MSG_ERROR("Directory specified with --with-jdk4_3 does not exist")
	  fi
	  ;;
    esac
    ])
AC_MSG_RESULT(done)


#AC_PROG_JAVA_WORKS (jdk_path, min_acceptable_ver, max_acceptable_ver)

AC_DEFUN([AC_PROG_JAVA_WORKS], [
ac_jw_jdk="$1"
ac_jw_min_minor="$2"
ac_jw_max_minor="$3"
ac_cv_prog_java_works=no
#echo macro called with ac_jw_jdk="$ac_jw_jdk" ac_jw_min_minor="$ac_jw_min_minor" ac_jw_max_minor="$ac_jw_max_minor"
if test "x$ac_jw_jdk" != "xnone" ; then
  AC_MSG_CHECKING([for working Java 1.$ac_jw_min_minor.x-1.$ac_jw_max_minor.x in $ac_jw_jdk])
  if test -x "$ac_jw_jdk/Commands/java"; then
    ac_jw_jdk="$ac_jw_jdk/Commands"
  else
    ac_jw_jdk="$ac_jw_jdk/bin"
  fi
  JAVAC=$ac_jw_jdk/javac
  JAVA=$ac_jw_jdk/java
  ac_java_version=`$JAVA -version 2>&1 | grep ' version' | cut -f 2 -d '"'`
  ac_java_ver_major=`echo $ac_java_version | cut -f 1 -d .`
  ac_java_ver_minor=`echo $ac_java_version | cut -f 2 -d .`
  if test "0$ac_java_ver_major" -gt "1"
  then
    if test "0$ac_java_ver_major" -lt "0$ac_jw_min_minor" -o "0$ac_java_ver_major" -gt "0$ac_jw_max_minor"
    then
      AC_MSG_ERROR([wrong version ($ac_java_ver_major.$ac_java_ver_minor)])
    fi
  elif test "0$ac_java_ver_minor" -lt "0$ac_jw_min_minor" -o "0$ac_java_ver_minor" -gt "0$ac_jw_max_minor"
  then
      AC_MSG_ERROR([wrong version ($ac_java_ver_major.$ac_java_ver_minor)])
  fi
  JAVA_TEST=Test.java
  CLASS_TEST=Test.class
  TEST=Test
  changequote(, )dnl
  cat << \EOF > $JAVA_TEST
/* [#]line __oline__ "configure" */
public class Test {
public static void main (String args[]) {
  System.exit (0);
} }
EOF
  changequote([, ])dnl
  if AC_TRY_COMMAND($JAVAC $JAVACFLAGS $JAVA_TEST) && test -s $CLASS_TEST; then
    :
  else
    echo "configure: failed program was:" >&AC_FD_CC
    cat $JAVA_TEST >&AC_FD_CC
    AC_MSG_ERROR(The Java compiler $JAVAC failed (see config.log, check the CLASSPATH?))
  fi
  if AC_TRY_COMMAND($JAVA $JAVAFLAGS $TEST) >/dev/null 2>&1; then
    ac_cv_prog_java_works=yes
  else
    echo "configure: failed program was:" >&AC_FD_CC
    cat $JAVA_TEST >&AC_FD_CC
    AC_MSG_ERROR(The Java VM $JAVA failed (see config.log, check the CLASSPATH?))
  fi
  rm -fr $JAVA_TEST $CLASS_TEST Test.uue
  AC_MSG_RESULT(found)
fi
])

#
#  Removed support for JDK1.2 - JDK1.5
#
AM_CONDITIONAL(WITH_JDK2, false)
AM_CONDITIONAL(WITH_JDK3, false)

AC_PROG_JAVA_WORKS($ac_jdk4_path, 6, 6)
ac_jdk4_works="$ac_cv_prog_java_works"
ac_jdk4_path="$ac_jw_jdk"
AM_CONDITIONAL(WITH_JDK4, test "x$ac_jdk4_works" = "xyes")
AC_SUBST(ac_jdk4_path)

AC_PROG_JAVA_WORKS($ac_jdk4_1_path, 7, 7)
ac_jdk4_1_works="$ac_cv_prog_java_works"
ac_jdk4_1_path="$ac_jw_jdk"
AM_CONDITIONAL(WITH_JDK4_1, test "x$ac_jdk4_1_works" = "xyes")
AC_SUBST(ac_jdk4_1_path)

AC_PROG_JAVA_WORKS($ac_jdk4_2_path, 8, 8)
ac_jdk4_2_works="$ac_cv_prog_java_works"
ac_jdk4_2_path="$ac_jw_jdk"
AM_CONDITIONAL(WITH_JDK4_2, test "x$ac_jdk4_2_works" = "xyes")
AC_SUBST(ac_jdk4_2_path)

AC_PROG_JAVA_WORKS($ac_jdk4_3_path, 9, 15)
ac_jdk4_3_works="$ac_cv_prog_java_works"
ac_jdk4_3_path="$ac_jw_jdk"
AM_CONDITIONAL(WITH_JDK4_3, test "x$ac_jdk4_3_works" = "xyes")
AC_SUBST(ac_jdk4_3_path)

ac_integ_jdk=""
if test "x$ac_jdk4_3_works" = "xyes" ; then
  ac_integ_jdk="$ac_jdk4_3_path/.."
elif test "x$ac_jdk4_2_works" = "xyes" ; then
  ac_integ_jdk="$ac_jdk4_2_path/.."
elif test "x$ac_jdk4_1_works" = "xyes" ; then
  ac_integ_jdk="$ac_jdk4_1_path/.."
elif test "x$ac_jdk4_works" = "xyes" ; then
  ac_integ_jdk="$ac_jdk4_path/.."
fi

if test "x$ac_integ_jdk" != "x" ; then
    integ_jdk_CPPFLAGS=""
    integ_jdk_LDFLAGS=""
    ac_save_CPPFLAGS="$CPPFLAGS"
    #supported jvm hosting platforms : add more here
    case $host in
	x86_64-*-linux*)
                CPPFLAGS="$CPPFLAGS -I$ac_integ_jdk/include -I$ac_integ_jdk/include/linux"
        	AC_CHECK_HEADERS(jni.h,
			[ java_CPPFLAGS="-I$ac_integ_jdk/include -I$ac_integ_jdk/include/linux" ],
			[ ac_integ_jdk="" ])
		AC_CHECK_LIB(jvm, JNI_GetDefaultJavaVMInitArgs,
			[ java_LDFLAGS="-L$ac_integ_jdk/jre/lib/amd64/server -R$ac_integ_jdk/jre/lib/amd64/server -ljvm" ],
			[ ac_integ_jdk="" ],
			[ "-L$ac_integ_jdk/jre/lib/amd64/server"])
		;;
	i?86-*-linux*)
                CPPFLAGS="$CPPFLAGS -I$ac_integ_jdk/include -I$ac_integ_jdk/include/linux"
        	AC_CHECK_HEADERS(jni.h,
			[ java_CPPFLAGS="-I$ac_integ_jdk/include -I$ac_integ_jdk/include/linux" ],
			[ ac_integ_jdk="" ])
		AC_CHECK_LIB(jvm, JNI_GetDefaultJavaVMInitArgs,
			[ java_LDFLAGS="-L$ac_integ_jdk/jre/lib/i386/server -ljvm" ],
			[ ac_integ_jdk="" ],
			[ "-L$ac_integ_jdk/jre/lib/i386/server"])
		;;
	sparc-*-solaris*)
                CPPFLAGS="$CPPFLAGS -I$ac_integ_jdk/include -I$ac_integ_jdk/include/solaris"
        	AC_CHECK_HEADERS(jni.h,
			[ java_CPPFLAGS="-I$ac_integ_jdk/include -I$ac_integ_jdk/include/solaris" ],
			[ ac_integ_jdk="" ])
		AC_CHECK_LIB(jvm, JNI_GetDefaultJavaVMInitArgs,
			[ java_LDFLAGS="-L$ac_integ_jdk/lib/jre/sparc/server -ljvm" ],
			[ ac_integ_jdk="" ],
			[ "-L$ac_integ_jdk/jre/lib/sparc/server"])
		;;
	hppa-*-hpux*)
                CPPFLAGS="$CPPFLAGS -I$ac_integ_jdk/include -I$ac_integ_jdk/include/hp-ux"
        	AC_CHECK_HEADERS(jni.h,
			[ java_CPPFLAGS="-I$ac_integ_jdk/include -I$ac_integ_jdk/include/hp-ux" ],
			[ ac_integ_jdk="" ])
		AC_CHECK_LIB(jvm, JNI_GetDefaultJavaVMInitArgs,
			[ java_LDFLAGS="-L$ac_integ_jdk/jre/lib/PA_RISC/server -ljvm" ],
			[ ac_integ_jdk="" ],
			[ "-L$ac_integ_jdk/jre/PA_RISC/sparc/server"])
		;;
	hppa2.0-*-hpux*)
                CPPFLAGS="$CPPFLAGS -I$ac_integ_jdk/include -I$ac_integ_jdk/include/hp-ux"
        	AC_CHECK_HEADERS(jni.h,
			[ java_CPPFLAGS="-I$ac_integ_jdk/include -I$ac_integ_jdk/include/hp-ux" ],
			[ ac_integ_jdk="" ])
		AC_CHECK_LIB(jvm, JNI_GetDefaultJavaVMInitArgs,
			[ java_LDFLAGS="-L$ac_integ_jdk/jre/lib/PA_RISC2.0/server -ljvm" ],
			[ ac_integ_jdk="" ],
			[ "-L$ac_integ_jdk/jre/PA_RISC2.0/sparc/server"])
		;;
	*-darwin*)
                CPPFLAGS="$CPPFLAGS -I/System/Library/Frameworks/JavaVM.framework/Headers"
        	AC_CHECK_HEADERS(jni.h,
			[
			 java_CPPFLAGS="-I/System/Library/Frameworks/JavaVM.framework/Headers"
			 java_LDFLAGS="-framework JavaVM"
			],
			[ ac_integ_jdk="" ])
		;;
		*)
		ac_integ_jdk=""
		;;
    esac
    CPPFLAGS="$ac_save_CPPFLAGS"
fi

if test "x$ac_integ_jdk" != "x" ; then
  AC_MSG_RESULT([Java JNI C flags="$java_CPPFLAGS"])
  AC_MSG_RESULT([Java JNI LD flags="$java_LDFLAGS"])
fi
AC_SUBST(java_CPPFLAGS)
AC_SUBST(java_LDFLAGS)
AM_CONDITIONAL(INTEG_JDK, test "x$ac_integ_jdk" != "x")


##########################################################################
#                                                                        #
# Default SQL port	                                                 #
#                                                                        #
##########################################################################

PORT=1111
AC_ARG_WITH(port, [dnl
AC_HELP_STRING([--with-port(=NUMBER)], [SQL port (1111 default)])dnl
], [ PORT=${withval}])
AC_SUBST(PORT)


##########################################################################
#                                                                        #
# Control building of VAD packages                                       #
#                                                                        #
##########################################################################
AC_ARG_ENABLE([],[
VAD Packages:],[])

AC_ARG_ENABLE(bpel-vad, [dnl
AC_HELP_STRING([--enable-bpel-vad], [enable BPEL vad])
AC_HELP_STRING([--disable-bpel-vad], [disable BPEL vad (default)])dnl
], [
     case "${enableval}" in
       yes)	with_bpel_vad="yes";;
       no)	with_bpel_vad="no";;
       *)	AC_MSG_ERROR(bad value ${enableval} for --enable-bpel-vad) ;;
     esac
  ],
  [ with_bpel_vad="no" ]
)

AC_ARG_ENABLE(conductor-vad, [dnl
AC_HELP_STRING([--enable-conductor-vad], [enable Conductor vad package (default)])
AC_HELP_STRING([--disable-conductor-vad], [disable Conductor vad package])dnl
], [
     case "${enableval}" in
       yes)	with_conductor_vad="yes";;
       no)	with_conductor_vad="no";;
       *)	AC_MSG_ERROR(bad value ${enableval} for --enable-conductor-vad) ;;
     esac
  ],
  [ with_conductor_vad="yes" ]
)

AC_ARG_ENABLE(dbpedia-vad, [dnl
AC_HELP_STRING([--enable-dbpedia-vad], [enable DBpedia vad package])
AC_HELP_STRING([--disable-dbpedia-vad], [disable DBpedia vad package (default)])dnl
], [
     case "${enableval}" in
       yes)	with_dbpedia_vad="yes";;
       no)	with_dbpedia_vad="no";;
       *)	AC_MSG_ERROR(bad value ${enableval} for --enable-dbpedia-vad) ;;
     esac
  ],
  [ with_dbpedia_vad="no" ]
)

AC_ARG_ENABLE(demo-vad, [dnl
AC_HELP_STRING([--enable-demo-vad], [enable Demo vad package])
AC_HELP_STRING([--disable-demo-vad], [disable Demo vad package (default)])dnl
], [
     case "${enableval}" in
       yes)	with_demo_vad="yes";;
       no)	with_demo_vad="no";;
       *)	AC_MSG_ERROR(bad value ${enableval} for --enable-demo-vad) ;;
     esac
  ],
  [ with_demo_vad="no" ]
)

AC_ARG_ENABLE(fct-vad, [dnl
AC_HELP_STRING([--enable-fct-vad], [enable Facet Browser vad package])
AC_HELP_STRING([--disable-fct-vad], [disable Facet Browser vad package (default)])dnl
], [
     case "${enableval}" in
       yes)	with_fct_vad="yes";;
       no)	with_fct_vad="no";;
       *)	AC_MSG_ERROR(bad value ${enableval} for --enable-fct-vad) ;;
     esac
  ],
  [ with_fct_vad="no" ]
)

AC_ARG_ENABLE(isparql-vad, [dnl
AC_HELP_STRING([--enable-isparql-vad], [enable iSPARQL vad package])
AC_HELP_STRING([--disable-isparql-vad], [disable iSPARQL vad package (default)])dnl
], [
     case "${enableval}" in
       yes)	with_isparql_vad="yes";;
       no)	with_isparql_vad="no";;
       *)	AC_MSG_ERROR(bad value ${enableval} for --enable-isparql-vad) ;;
     esac
  ],
  [ with_isparql_vad="yes" ]
)

AC_ARG_ENABLE(ods-vad, [dnl
AC_HELP_STRING([--enable-ods-vad], [enable ODS vad packages])
AC_HELP_STRING([--disable-ods-vad], [disable ODS vad packages (default)])dnl
], [
     case "${enableval}" in
       yes)	with_ods_vad="yes";;
       no)	with_ods_vad="no";;
       *)	AC_MSG_ERROR(bad value ${enableval} for --enable-ods-vad) ;;
     esac
  ],
  [ with_ods_vad="no" ]
)

AC_ARG_ENABLE(rdfmappers-vad, [dnl
AC_HELP_STRING([--enable-rdfmappers-vad], [enable RDF Mappers vad package])
AC_HELP_STRING([--disable-rdfmappers-vad], [disable RDF Mappers vad package (default)])dnl
], [
     case "${enableval}" in
       yes)	with_rdfmappers_vad="yes";;
       no)	with_rdfmappers_vad="no";;
       *)	AC_MSG_ERROR(bad value ${enableval} for --enable-rdfmappers-vad) ;;
     esac
  ],
  [ with_rdfmappers_vad="no" ]
)

AC_ARG_ENABLE(rdb2rdf-vad, [dnl
AC_HELP_STRING([--enable-rdb2rdf-vad], [enable Rdb2Rdf vad package])
AC_HELP_STRING([--disable-rdb2rdf-vad], [disable Rdb2Rdf vad package (default)])dnl
], [
     case "${enableval}" in
       yes)	with_rdb2rdf_vad="yes";;
       no)	with_rdb2rdf_vad="no";;
       *)	AC_MSG_ERROR(bad value ${enableval} for --enable-rdb2rdf-vad) ;;
     esac
  ],
  [ with_rdb2rdf_vad="no" ]
)

AC_ARG_ENABLE(sparqldemo-vad, [dnl
AC_HELP_STRING([--enable-sparqldemo-vad], [enable Sparql Demo vad package])
AC_HELP_STRING([--disable-sparqldemo-vad], [disable Sparql Demo vad package (default)])dnl
], [
     case "${enableval}" in
       yes)	with_sparqldemo_vad="yes";;
       no)	with_sparqldemo_vad="no";;
       *)	AC_MSG_ERROR(bad value ${enableval} for --enable-sparqldemo-vad) ;;
     esac
  ],
  [ with_sparqldemo_vad="no" ]
)

AC_ARG_ENABLE(syncml-vad, [dnl
AC_HELP_STRING([--enable-syncml-vad], [enable SyncML vad package])
AC_HELP_STRING([--disable-syncml-vad], [disable SyncML vad package (default)])dnl
], [
     case "${enableval}" in
       yes)	with_syncml_vad="yes";;
       no)	with_syncml_vad="no";;
       *)	AC_MSG_ERROR(bad value ${enableval} for --enable-syncml-vad) ;;
     esac
  ],
  [ with_syncml_vad="no" ]
)

AC_ARG_ENABLE(tutorial-vad, [dnl
AC_HELP_STRING([--enable-tutorial-vad], [enable Tutorial vad package])
AC_HELP_STRING([--disable-tutorial-vad], [disable Tutorial vad package (default)])dnl
], [
     case "${enableval}" in
       yes)	with_tutorial_vad="yes";;
       no)	with_tutorial_vad="no";;
       *)	AC_MSG_ERROR(bad value ${enableval} for --enable-tutorial-vad) ;;
     esac
  ],
  [ with_tutorial_vad="no" ]
)

AC_ARG_ENABLE(websockets-vad, [dnl
AC_HELP_STRING([--enable-websockets-vad], [enable Websockets Demo vad package])
AC_HELP_STRING([--disable-websockets-vad], [disable Websockets Demo vad package (default)])dnl
], [
     case "${enableval}" in
       yes)	with_websockets_vad="yes";;
       no)	with_websockets_vad="no";;
       *)	AC_MSG_ERROR(bad value ${enableval} for --enable-websockets-vad) ;;
     esac
  ],
  [ with_websockets_vad="no" ]
)



AC_ARG_ENABLE(all-vads, [dnl
AC_HELP_STRING([--disable-all-vads], [disable building all vad packages])dnl
], [
     case "${enableval}" in
       yes)	with_all_vad="yes";;
       no)	with_all_vad="no";;
       *)	AC_MSG_ERROR(bad value ${enableval} for --enable-all-vads) ;;
     esac
  ],
  [ with_all_vad="no_change" ]
)

if test "x$with_all_vad" != "xno_change"
then
    with_bpel_vad="$with_all_vad"
    with_conductor_vad="$with_all_vad"
    with_dbpedia_vad="$with_all_vad"
    with_demo_vad="$with_all_vad"
    with_fct_vad="$with_all_vad"
    with_isparql_vad="$with_all_vad"
    with_ods_vad="$with_all_vad"
    with_rdb2rdf_vad="$with_all_vad"
    with_rdfmappers_vad="$with_all_vad"
    with_sparqldemo_vad="$with_all_vad"
    with_syncml_vad="$with_all_vad"
    with_tutorial_vad="$with_all_vad"
    with_websockets_vad="$with_all_vad"
fi

AM_CONDITIONAL(WITH_BPEL_VAD, test "x$with_bpel_vad" = "xyes")
AM_CONDITIONAL(WITH_CONDUCTOR_VAD, test "x$with_conductor_vad" = "xyes")
AM_CONDITIONAL(WITH_DBPEDIA_VAD, test "x$with_dbpedia_vad" = "xyes")
AM_CONDITIONAL(WITH_DEMO_VAD, test "x$with_demo_vad" = "xyes")
AM_CONDITIONAL(WITH_FCT_VAD, test "x$with_fct_vad" = "xyes")
AM_CONDITIONAL(WITH_ISPARQL_VAD, test "x$with_isparql_vad" = "xyes")
AM_CONDITIONAL(WITH_ODS_VAD, test "x$with_ods_vad" = "xyes")
AM_CONDITIONAL(WITH_RDB2RDF_VAD, test "x$with_rdb2rdf_vad" = "xyes")
AM_CONDITIONAL(WITH_RDFMAPPERS_VAD, test "x$with_rdfmappers_vad" = "xyes")
AM_CONDITIONAL(WITH_SPARQLDEMO_VAD, test "x$with_sparqldemo_vad" = "xyes")
AM_CONDITIONAL(WITH_SYNCML_VAD, test "x$with_syncml_vad" = "xyes")
AM_CONDITIONAL(WITH_TUTORIAL_VAD, test "x$with_tutorial_vad" = "xyes")
AM_CONDITIONAL(WITH_WEBSOCKETS_VAD, test "x$with_websockets_vad" = "xyes")



##########################################################################
##									##
##  Operating System extentions						##
##									##
##########################################################################

AC_MSG_CHECKING([for OS specific configuration])
dnl
dnl All system specific configuration items go in here
dnl
dnl NOTE : PLEASE CHANGE mklic.c WHEN THESE ENTRIES ARE MODIFIED
dnl
OPSYS="Unknown"

case $host in

*-sco3.2v4*)
	OPSYS="SCO UNIX"
	;;

*-sco*)
	OPSYS="SCO OpenServer"
	;;

*-linux*)
  	OPSYS="Linux"
	;;

*-aix*)
	OPSYS="AIX"
	;;

*-hpux*)
	OPSYS="HP/UX"
	;;

*-solaris*)
	OPSYS="Solaris"
	;;

*-sunos*)
	OPSYS="SunOS"
	;;

*-freebsd*)
	OPSYS="FreeBSD"
	;;

*-dgux*)
	OPSYS="DG/UX"
	;;

*-irix-5*)
	OPSYS="IRIX"
	;;

*-irix*)
	OPSYS="IRIX"
	;;

alpha-dec-osf*)
	OPSYS="Digital Unix (OSF/1)"
	;;

*-netbsd*)
	OPSYS="NetBSD"
	;;

*-freebsd*)
	OPSYS="FreeBSD"
	;;

*-nextstep*)
	OPSYS="NextSTEP"
	;;

*-ultrix*)
	OPSYS="Ultrix"
	;;

*-sni-sysv*)
	OPSYS="SINIX"
	;;

*-sequent*)
	OPSYS="DYNIX/ptx"
	;;

*-univel-sysv*)
	#
	# Actually this is (NOVELL|SCO) NetWare
	#
	OPSYS="Generic SYSV"
	;;

*-unknown-sysv*)
	OPSYS="Generic SYSV"
	;;

*-riscos*)
	OPSYS="RiscOS"
	;;

*-pc-bsdi*)
	OPSYS="BSDI"
	;;

*-darwin20*)
	OPSYS="Mac\ OS\ 11"
	;;

*-darwin*)
	OPSYS="Mac\ OS\ X"
	;;

*)
	OPSYS="UNKNOWN"
	;;

esac
AC_MSG_RESULT(($OPSYS))

dnl
dnl Now substitute all variables back
dnl
AC_SUBST(OPSYS)

CCPLATFORMDEFS=""
case $host in

*-linux*)
	CCPLATFORMDEFS="-Dlinux -D_GNU_SOURCE -DFILE64 -D_LARGEFILE64_SOURCE"
        if test "$have_mono" = "yes"
        then
	  CCOPT="$CCOPT -DMONO_USE_EXC_TABLES -fexceptions -D_REENTRANT -D_GNU_SOURCE"
	  VLIBS="-ldl -lrt $VLIBS"
        fi
	case $host in
	    sparc*)
 	        CCPLATFORMDEFS="$CCPLATFORMDEFS -DNEW_HASH_NEED_ALIGN" ;;
	esac
	;;

*-hpux10*)
	CCPLATFORMDEFS="-DHPUX_10"
	;;

*-hpux11*)
	CCPLATFORMDEFS="-DHPUX_11"
	;;

*-solaris*)
	CCPLATFORMDEFS="-DSOLARIS -DFILE64 -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64"
	case $host in
	    sparc*)
 	    CCPLATFORMDEFS="$CCPLATFORMDEFS -DNEW_HASH_NEED_ALIGN" ;;
	esac
	;;

*-aix*)
	CCPLATFORMDEFS="-DAIX -DFILE64  -D_LARGE_FILE_API"
	;;
*)
	;;

esac
AC_MSG_CHECKING([for OS specific defines])
AC_MSG_RESULT(($CCPLATFORMDEFS))
AC_SUBST(CCPLATFORMDEFS)
AC_SUBST(CCOPT)
LIBS="$VLIBS $LIBS"
AC_MSG_CHECKING([for system libs])
AC_MSG_RESULT($VLIBS)
AC_SUBST(LIBS)
AC_SUBST(AM_LDFLAGS)
AC_SUBST(ccincl)
AC_MSG_RESULT(Configured: $BUILD_OPTS)

#AC_CONFIG_SUBDIRS(libsrc/zlib)

AC_DEFINE([VIRTTP], 1, [TP code])
AC_DEFINE([INC_BACKUP], 1, [Inc backup])
AC_DEFINE([INPROCESS_CLIENT], 1, [inprocess client])
AC_DEFINE([BIF_TIDY], 1, [tidy functions])
AC_DEFINE([REPLICATION_SUPPORT], 1, [replication])
AC_DEFINE([REPLICATION_SUPPORT2], 1, [replication 2])
AC_DEFINE([VIRTUAL_DIR], 1, [virtual dirs])

AC_SUBST(srvrlibs)
AC_SUBST(clntlibs)


##########################################################################
##									##
##  Flags formerly in Makeconfig					##
##									##
##########################################################################

VIRT_AM_CFLAGS="$CCOPT $CCWARN $CCDEBUG $CCDEFS $ccincl $CCPLATFORMDEFS $DEFS $INCL"

AC_SUBST(VIRT_AM_CFLAGS)
AC_SUBST(SYSLIBS)


##########################################################################
##									##
##  Generate the files using the above information			##
##									##
##########################################################################
AC_CONFIG_FILES([
	Makefile
	binsrc/Makefile
	docsrc/Makefile
	libsrc/Makefile
	binsrc/bpel/Makefile
	binsrc/cached_resources/Makefile
	binsrc/dav/Makefile
	binsrc/dbpedia/Makefile
	binsrc/driver/Makefile
	binsrc/fct/Makefile
	binsrc/graphql/Makefile
	binsrc/hibernate/Makefile
	binsrc/hosting/Makefile
	binsrc/hosting/mono/Makefile
	binsrc/hosting/mono/tests/Makefile
	binsrc/hosting/geos/Makefile
	binsrc/hosting/perl/Makefile
	binsrc/hosting/php/Makefile
	binsrc/hosting/proj4/Makefile
	binsrc/hosting/python/Makefile
	binsrc/hosting/ruby/Makefile
	binsrc/hosting/shapefileio/Makefile
	binsrc/isparql/Makefile
	binsrc/jena/Makefile
	binsrc/jena2/Makefile
	binsrc/jena3/Makefile
	binsrc/jena4/Makefile
	binsrc/maildrop/Makefile
	binsrc/mono/Makefile
	binsrc/oat/Makefile
	binsrc/rdf_mappers/Makefile
	binsrc/rdb2rdf/Makefile
	binsrc/rdf4j/Makefile
	binsrc/rdf4j_4/Makefile
	binsrc/redland/Makefile
	binsrc/samples/demo/Makefile
	binsrc/samples/hslookup/Makefile
	binsrc/samples/image_magick/Makefile
	binsrc/samples/JDBC/Makefile
	binsrc/samples/Makefile
	binsrc/samples/odp/Makefile
	binsrc/samples/sparql_demo/Makefile
	binsrc/samples/wbxml2/Makefile
	binsrc/samples/webapp/Makefile
	binsrc/samples/xpath/Makefile
	binsrc/samples/xquery/Makefile
	binsrc/sesame/Makefile
	binsrc/sesame2/Makefile
	binsrc/sesame3/Makefile
	binsrc/sesame4/Makefile
	binsrc/sqldoc/Makefile
	binsrc/sync/Makefile
	binsrc/tests/biftest/Makefile
	binsrc/tests/dotnet/Makefile
	binsrc/tests/Makefile
	binsrc/tests/bsbm/Makefile
	binsrc/tests/lubm/Makefile
	binsrc/tests/oledb/Makefile
	binsrc/tests/rdf/Makefile
	binsrc/tests/suite/Makefile
	binsrc/tests/suite/tpc-d/Makefile
	binsrc/tests/tpcrun/Makefile
	binsrc/tests/wb/Makefile
	binsrc/tutorial/apps/Makefile
	binsrc/tutorial/hosting/Makefile
	binsrc/tutorial/Makefile
	binsrc/tutorial/services/Makefile
	binsrc/tutorial/web/Makefile
	binsrc/tutorial/xml/Makefile
	binsrc/vad/Makefile
	binsrc/virtodbc/Makefile
	binsrc/virtoledb/Makefile
	binsrc/VirtuosoClient.Net/Makefile
	binsrc/virtuoso/Makefile
	binsrc/virtuoso_sink/Makefile
	binsrc/vsp/Makefile
	binsrc/vspx/Makefile
	binsrc/websocket/Makefile
	binsrc/ws/Makefile
	binsrc/ws/wsrm/Makefile
	binsrc/xddl/Makefile
	binsrc/conductor/Makefile
	docsrc/chm/Makefile
	docsrc/docwiki/Makefile
	docsrc/html_virt/Makefile
	docsrc/images/Makefile
	docsrc/pdf/Makefile
	docsrc/releasenotes/Makefile
	docsrc/styleguide/Makefile
	docsrc/stylesheets/Makefile
	docsrc/xmlsource/Makefile
	libsrc/Dk/Makefile
	libsrc/JDBCDriverType4/Makefile
	libsrc/JDBCDriverType4/testsuite_4.0/Makefile
	libsrc/JDBCDriverType4/virtuoso/jdbc/Makefile
	libsrc/JDBCDriverType4/virtuoso/Makefile
	libsrc/langfunc/Makefile
	libsrc/odbcsdk/Makefile
	libsrc/plugin/Makefile
	libsrc/Thread/Makefile
	libsrc/Tidy/Makefile
	libsrc/util/Makefile
	libsrc/Wi/Makefile
	libsrc/Xml.new/Makefile
	libsrc/zlib/Makefile
	appsrc/Makefile
	appsrc/ODS-Framework/Makefile
	appsrc/ODS-Addressbook/Makefile
	appsrc/ODS-Blog/Makefile
	appsrc/ODS-Bookmark/Makefile
	appsrc/ODS-Briefcase/Makefile
	appsrc/ODS-Calendar/Makefile
	appsrc/ODS-Community/Makefile
	appsrc/ODS-Discussion/Makefile
	appsrc/ODS-FeedManager/Makefile
	appsrc/ODS-Gallery/Makefile
	appsrc/ODS-Polls/Makefile
	appsrc/ODS-WebMail/Makefile
	appsrc/ODS-Wiki/Makefile
	appsrc/ODS-Wiki/plugin/Makefile
])

AC_CONFIG_COMMANDS([default], [
	chmod 755 bin/makever
])

AC_OUTPUT


##########################################################################
##									##
##  Display configuration information					##
##									##
##########################################################################
B=`tput bold 2>/dev/null`
N=`tput sgr0 2>/dev/null`

echo ""
echo ""
echo "${B}${PACKAGE_STRING} configuration summary${N}"
echo "${PACKAGE_STRING} configuration summary" | sed 's/./=/g'
echo ""
echo "${B}Installation variables${N}"
echo "AC_HELP_STRING(layout,		[${virtuoso_layout}])"
echo "AC_HELP_STRING(prefix,		[${prefix}])"
echo "AC_HELP_STRING(exec_prefix,	[${exec_prefix}])"
echo ""
echo "${B}Installation paths${N}"
echo "AC_HELP_STRING(programs,		[${bindir}])"
echo "AC_HELP_STRING(include files, 	[${includedir}])"
echo "AC_HELP_STRING(libraries, 	[${libdir}])"
echo "AC_HELP_STRING(manual pages, 	[${mandir}])"
echo "AC_HELP_STRING(vad packages, 	[${vaddir}])"
echo "AC_HELP_STRING(database, 		[${dbdir}])"
echo "AC_HELP_STRING(hosting, 		[${hostingdir}])"
echo
echo "${B}Options${N}"
echo "AC_HELP_STRING(BUILD_OPTS,	[${BUILD_OPTS}])"
echo ""

exit 0
